-
-
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 userEvent proof of concept
- Loading branch information
1 parent
a50330e
commit 400986c
Showing
7 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Page } from 'playwright' | ||
import type { UserEvent } from '../../../context' | ||
import type { UserEventCommand } from './utils' | ||
|
||
// TODO: options | ||
export const click: UserEventCommand<UserEvent['click']> = async ( | ||
{ provider }, | ||
element, | ||
options, | ||
) => { | ||
if (provider.name === 'playwright') { | ||
const page = (provider as any).page as Page | ||
await page.frameLocator('#vitest-tester-frame').locator(element).click(options) | ||
} | ||
if (provider.name === 'webdriverio') { | ||
// TODO: test | ||
const page = (provider as any).browser as WebdriverIO.Browser | ||
const frame = await page.findElement('css selector', '#vitest-tester-frame') | ||
await page.switchToFrame(frame) | ||
;(await page.$(element)).click(options) | ||
} | ||
} |
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,10 @@ | ||
import type { BrowserCommand } from 'vitest/node' | ||
|
||
export type UserEventCommand<T extends (...args: any) => any> = BrowserCommand< | ||
ConvertUserEventParameters<Parameters<T>> | ||
> | ||
|
||
type ConvertElementToLocator<T> = T extends Element ? string : T | ||
type ConvertUserEventParameters<T extends unknown[]> = { | ||
[K in keyof T]: ConvertElementToLocator<T[K]> | ||
} |
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,17 @@ | ||
import { userEvent } from '@vitest/browser/context' | ||
import { test, vi } from 'vitest' | ||
|
||
test('clicks on an element', async () => { | ||
const button = document.createElement('button') | ||
button.textContent = 'Hello World' | ||
const fn = vi.fn() | ||
button.onclick = () => { | ||
fn() | ||
} | ||
document.body.appendChild(button) | ||
|
||
await userEvent.click(button, { | ||
timeout: 2000, | ||
}) | ||
// expect(fn).toHaveBeenCalled() | ||
}) |