Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser): fail playwright timeouts earlier than a test timeout #7565

Merged
merged 14 commits into from
Mar 7, 2025
Merged
3 changes: 2 additions & 1 deletion docs/guide/browser/interactivity-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ References:
## userEvent.clear

```ts
function clear(element: Element | Locator): Promise<void>
function clear(element: Element | Locator, options?: UserEventClearOptions): Promise<void>
```

This method clears the input element content.
Expand Down Expand Up @@ -451,6 +451,7 @@ References:
function upload(
element: Element | Locator,
files: string[] | string | File[] | File,
options?: UserEventUploadOptions,
): Promise<void>
```

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/browser/locators.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Locators | Browser Mode
outline: [2, 3]
---

# Locators <Version>2.1.0</Version>
# Locators

A locator is a representation of an element or a number of elements. Every locator is defined by a string called a selector. Vitest abstracts this selector by providing convenient methods that generate those selectors behind the scenes.

Expand Down Expand Up @@ -505,7 +505,7 @@ await page.getByRole('img', { name: 'Rose' }).tripleClick()
### clear

```ts
function clear(): Promise<void>
function clear(options?: UserEventClearOptions): Promise<void>
```

Clears the input element content.
Expand Down
10 changes: 6 additions & 4 deletions packages/browser/context.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export interface UserEvent {
* @see {@link https://webdriver.io/docs/api/element/clearValue} WebdriverIO API
* @see {@link https://testing-library.com/docs/user-event/utility/#clear} testing-library API
*/
clear: (element: Element | Locator) => Promise<void>
clear: (element: Element | Locator, options?: UserEventClearOptions) => Promise<void>
/**
* Sends a `Tab` key event. Uses provider's API under the hood.
* @see {@link https://playwright.dev/docs/api/class-keyboard} Playwright API
Expand Down Expand Up @@ -171,7 +171,7 @@ export interface UserEvent {
* @see {@link https://playwright.dev/docs/api/class-locator#locator-set-input-files} Playwright API
* @see {@link https://testing-library.com/docs/user-event/utility#upload} testing-library API
*/
upload: (element: Element | Locator, files: File | File[] | string | string[]) => Promise<void>
upload: (element: Element | Locator, files: File | File[] | string | string[], options?: UserEventUploadOptions) => Promise<void>
/**
* Copies the selected content.
* @see {@link https://playwright.dev/docs/api/class-keyboard} Playwright API
Expand Down Expand Up @@ -218,9 +218,11 @@ export interface UserEventFillOptions {}
export interface UserEventHoverOptions {}
export interface UserEventSelectOptions {}
export interface UserEventClickOptions {}
export interface UserEventClearOptions {}
export interface UserEventDoubleClickOptions {}
export interface UserEventTripleClickOptions {}
export interface UserEventDragAndDropOptions {}
export interface UserEventUploadOptions {}

export interface LocatorOptions {
/**
Expand Down Expand Up @@ -358,7 +360,7 @@ export interface Locator extends LocatorSelectors {
* Clears the input element content
* @see {@link https://vitest.dev/guide/browser/interactivity-api#userevent-clear}
*/
clear(): Promise<void>
clear(options?: UserEventClearOptions): Promise<void>
/**
* Moves the cursor position to the selected element
* @see {@link https://vitest.dev/guide/browser/interactivity-api#userevent-hover}
Expand Down Expand Up @@ -391,7 +393,7 @@ export interface Locator extends LocatorSelectors {
* Change a file input element to have the specified files. Uses provider's API under the hood.
* @see {@link https://vitest.dev/guide/browser/interactivity-api#userevent-upload}
*/
upload(files: File | File[] | string | string[]): Promise<void>
upload(files: File | File[] | string | string[], options?: UserEventUploadOptions): Promise<void>

/**
* Make a screenshot of an element matching the locator.
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/matchers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ declare module 'vitest' {
interface ExpectStatic {
/**
* `expect.element(locator)` is a shorthand for `expect.poll(() => locator.element())`.
* You can set default timeout via `expect.poll.timeout` config.
* You can set default timeout via `expect.poll.timeout` option in the config.
* @see {@link https://vitest.dev/api/expect#poll}
*/
element: <T extends Element | Locator>(element: T, options?: ExpectPollOptions) => PromisifyDomAssertion<Awaited<Element | null>>
}
Expand Down
2 changes: 2 additions & 0 deletions packages/browser/providers/playwright.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type PWFillOptions = NonNullable<Parameters<Page['fill']>[2]>
type PWScreenshotOptions = NonNullable<Parameters<Page['screenshot']>[0]>
type PWSelectOptions = NonNullable<Parameters<Page['selectOption']>[2]>
type PWDragAndDropOptions = NonNullable<Parameters<Page['dragAndDrop']>[2]>
type PWSetInputFiles = NonNullable<Parameters<Page['setInputFiles']>[2]>

declare module '@vitest/browser/context' {
export interface UserEventHoverOptions extends PWHoverOptions {}
Expand All @@ -50,6 +51,7 @@ declare module '@vitest/browser/context' {
export interface UserEventFillOptions extends PWFillOptions {}
export interface UserEventSelectOptions extends PWSelectOptions {}
export interface UserEventDragAndDropOptions extends PWDragAndDropOptions {}
export interface UserEventUploadOptions extends PWSetInputFiles {}

export interface ScreenshotOptions extends PWScreenshotOptions {}

Expand Down
Loading