MCPcopy Create free account
hub / github.com/vercel/examples / createUtils

Function createUtils

internal/packages/playwright/src/shared/fixtures/utils.ts:4–19  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

2import { tid } from '../utils/data-testid'
3
4export const createUtils = (page: Page) => ({
5 /**
6 * Returns a locator that matches the given data-testid.
7 * @param args - The data-testid to match.
8 */
9 getByTestId: (...args: string[]) =>
10 page.locator(`data-testid=${tid(...args)}`),
11 getByTestIdWithinElement: (element: Locator, ...args: string[]) =>
12 element.locator(`data-testid=${tid(...args)}`),
13 /**
14 * Returns true when a viewport is mobile.
15 *
16 * Useful for when different selectors are needed at different screen sizes.
17 */
18 isMobileViewport: () => (page.viewportSize()?.width ?? 0) <= 600,
19})
20
21export type Utils = ReturnType<typeof createUtils>

Callers 1

setup-fixture.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected