-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(browser): support clipboard api
userEvent.copy, cut, paste
(#6769
- Loading branch information
Showing
7 changed files
with
228 additions
and
6 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
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
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,45 @@ | ||
import { expect, test } from 'vitest'; | ||
import { page, userEvent } from '@vitest/browser/context'; | ||
|
||
test('clipboard', async () => { | ||
// make it smaller since webdriverio fails when scaled | ||
page.viewport(300, 300) | ||
|
||
document.body.innerHTML = ` | ||
<input placeholder="first" /> | ||
<input placeholder="second" /> | ||
<input placeholder="third" /> | ||
`; | ||
|
||
// write first "hello" and copy to clipboard | ||
await userEvent.click(page.getByPlaceholder('first')); | ||
await userEvent.keyboard('hello'); | ||
await userEvent.dblClick(page.getByPlaceholder('first')); | ||
await userEvent.copy(); | ||
|
||
// paste into second | ||
await userEvent.click(page.getByPlaceholder('second')); | ||
await userEvent.paste(); | ||
|
||
// append first "world" and cut | ||
await userEvent.click(page.getByPlaceholder('first')); | ||
await userEvent.keyboard('world'); | ||
await userEvent.dblClick(page.getByPlaceholder('first')); | ||
await userEvent.cut(); | ||
|
||
// paste it to third | ||
await userEvent.click(page.getByPlaceholder('third')); | ||
await userEvent.paste(); | ||
|
||
expect([ | ||
(page.getByPlaceholder('first').element() as any).value, | ||
(page.getByPlaceholder('second').element() as any).value, | ||
(page.getByPlaceholder('third').element() as any).value, | ||
]).toMatchInlineSnapshot(` | ||
[ | ||
"", | ||
"hello", | ||
"helloworld", | ||
] | ||
`) | ||
}); |
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