-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
155 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'test-mule': minor | ||
--- | ||
|
||
Implement `user.clear()` | ||
|
||
Additionally, the default delay between keypresses in `user.type` has been decreased to 1ms. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { withBrowser } from 'test-mule'; | ||
|
||
test( | ||
'clears input element', | ||
withBrowser(async ({ user, utils, screen }) => { | ||
await utils.injectHTML(`<input />`); | ||
const input = await screen.getByRole('textbox'); | ||
await user.type(input, 'hiiiiiiii'); | ||
await expect(input).toHaveValue('hiiiiiiii'); | ||
await user.clear(input); | ||
await expect(input).toHaveValue(''); | ||
}), | ||
); | ||
|
||
test( | ||
'clears textarea element', | ||
withBrowser(async ({ user, utils, screen }) => { | ||
await utils.injectHTML(`<textarea>some text</textarea>`); | ||
const input = await screen.getByRole('textbox'); | ||
await expect(input).toHaveValue('some text'); | ||
await user.type(input, ' asdf{enter}hi'); | ||
await expect(input).toHaveValue('some text asdf\nhi'); | ||
await user.clear(input); | ||
await expect(input).toHaveValue(''); | ||
}), | ||
); | ||
|
||
test( | ||
'throws for contenteditable elements', | ||
withBrowser(async ({ user, utils, screen }) => { | ||
await utils.injectHTML(`<div contenteditable>text</div>`); | ||
const div = await screen.getByText(/text/); | ||
await expect(user.clear(div)).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"user.clear command is only available for <input> and textarea elements, received: <div contenteditable=\\"\\">text</div>"`, | ||
); | ||
}), | ||
); | ||
|
||
test( | ||
'throws for non-input elements', | ||
withBrowser(async ({ user, utils, screen }) => { | ||
await utils.injectHTML(`<div>text</div>`); | ||
const div = await screen.getByText(/text/); | ||
await expect(user.clear(div)).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"user.clear command is only available for <input> and textarea elements, received: <div>text</div>"`, | ||
); | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters