Skip to content

Commit 209dcd1

Browse files
committed
chore: cleanup
1 parent 2e0731d commit 209dcd1

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

docs/api/browser/locators.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -938,11 +938,13 @@ page.getByText('Hello USA').elements() // ✅ []
938938
### waitForElement <Version>4.1.0</Version> {#waitforelement}
939939

940940
```ts
941-
function waitForElement(options?: SelectorOptions): Promise<HTMLElement | SVGElement>
941+
function waitForElement(
942+
options?: SelectorOptions
943+
): Promise<HTMLElement | SVGElement>
942944
```
943945

944946
::: danger WARNING
945-
This is an escape hatch for library authors and 3d-party APIs that do not support locators directly. If you are interacting with the element, use [builtin methods](#methods) instead.
947+
This is an escape hatch for library authors and 3d-party APIs that do not support locators directly. If you are interacting with the element, use other [builtin methods](#methods) instead.
946948
:::
947949

948950
This method returns an element matching the locator. Unlike [`.element()`](#element), this method will wait and retry until a matching element appears in the DOM, using increasing intervals (0, 20, 50, 100, 100, 500ms).
@@ -953,7 +955,7 @@ If _multiple elements_ match the selector and `strict` is `true` (the default),
953955

954956
It accepts options:
955957

956-
- `timeout: number` - How long to wait in milliseconds until a single element is found. By default, this has the same timeout as the test.
958+
- `timeout: number` - How long to wait in milliseconds until at least one element is found. By default, this shares timeout with the test.
957959
- `strict: boolean` - When `true` (default), throws an error if multiple elements match the locator. When `false`, returns the first matching element.
958960

959961
Consider the following DOM structure:

packages/browser/context.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ export interface Locator extends LocatorSelectors {
715715
* This is an escape hatch for library authors and 3d-party APIs that do not support locators directly.
716716
* If you are interacting with the element, use builtin methods instead.
717717
* @since 4.1.0
718-
* @see {@link https://vitest.dev/api/browser/locators#waitForElement}
718+
* @see {@link https://vitest.dev/api/browser/locators#waitforelement}
719719
*/
720720
waitForElement(options?: SelectorOptions): Promise<HTMLElement | SVGElement>
721721
}

packages/browser/src/client/tester/context.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,16 @@ export const page: BrowserPage = {
323323
const name
324324
= options.path || `${taskName.replace(/[^a-z0-9]/gi, '-')}-${number}.png`
325325

326+
const [element, ...mask] = await Promise.all([
327+
options.element ? convertToSelector(options.element) : undefined,
328+
...('mask' in options
329+
? (options.mask as Array<Element | Locator>).map(convertToSelector)
330+
: []),
331+
])
332+
326333
const normalizedOptions = 'mask' in options
327-
? {
328-
...options,
329-
mask: await Promise.all((options.mask as Array<Element | Locator>).map(convertToSelector)),
330-
}
334+
? { ...options, mask }
331335
: options
332-
const element = options.element ? await convertToSelector(options.element) : undefined
333336

334337
return ensureAwaited(error => triggerCommand(
335338
'__vitest_screenshot',

0 commit comments

Comments
 (0)