allwright

API ReferenceTypeScriptVitest

Vitest

@allwright.dev/vitest layers Playwright-style test fixtures and retrying, negatable assertions on top of @allwright.dev/core, so a spec file never touches launch/config plumbing directly.

test

FunctionSince v0.0.24

A Vitest test extended with lazy web, Android, iOS, macOS, and Windows fixtures — nothing launches or connects until a fixture's method is first awaited.

test(name: string, fn: (ctx: { page: Page; browser: Browser; android: MobileAndroidDevice; androidApp: MobileAndroidApp; ios: MobileIosDevice; iosApp: MobileIosApp; macos: DesktopMacDesktop; macosApp: DesktopMacApp; windows: DesktopWindowsDesktop; windowsApp: DesktopWindowsApp }) => Promise<void>): void

Example

import { expect, test } from "@allwright.dev/vitest";

test("opens a page", async ({ page }) => {
  await page.goto("https://themoderninternet.vercel.app");
});

expect

FunctionSince v0.0.24

Vitest's expect, augmented: called with a web page/locator or native app/locator it returns retrying matchers for text, count, visibility, attachment, enabled/disabled, focus, editability, value, checked state, attributes, and bounds. URL and selection matchers remain web-only.

expect(actual: Page | NativeApp): PageExpectMatchers
expect(actual: Locator | NativeAppLocator): LocatorExpectMatchers

State matchers

MethodSince v0.1.14

Retrying web and native matchers re-read state on every attempt (default 5 s timeout, 100 ms interval; timeoutMs: 0 observes once). URL and selection matchers are web-only. A string URL must match exactly; null asserts a missing attribute or unsupported selection; selected options match in order by value, regex, or { value, label, index }; a box compares only the supplied fields. Each element matcher also has a page/app form taking a selector first.

toBeAttached(options?)
toBeVisible(options?)
toBeHidden(options?)
toBeEnabled(options?)
toBeDisabled(options?)
toBeFocused(options?)
toBeEditable(options?)
toHaveValue(expected: string | RegExp, options?)
toBeChecked(options?)
toHaveAttribute(name: string, expected: string | RegExp | null, options?)
toHaveBoundingBox(expected: Partial<BoundingBox> | null, options?)

// Web-only
toHaveURL(expected: string | RegExp, options?)
toHaveSelectedOptions(expected: SelectedOptionExpectation[], options?)
toHaveSelectedText(expected: string | RegExp | null, options?)

Example

await expect(page).toHaveURL(/\/dashboard(?:\?|$)/);
await expect(page.locator('select')).toHaveSelectedOptions([{ value: 'a', label: /Alpha/ }]);
await expect(page.locator('a')).toHaveAttribute('href', /dashboard/);
await expect(page.locator('input[type=radio]')).not().toBeChecked();

Negated assertions

MethodSince v0.1.3

Every matcher supports both the property form .not and the callable form .not() — matchers are immutable, so a second .not toggles back to positive.

expect(locator).not.toHaveText(expected)
expect(locator).not().toBeVisible()

Example

await expect(page.getByTestId('spinner')).not().toBeVisible();
await expect(page).not.toHaveCount('.error', 1);

allwrightVitestConfig

FunctionSince v0.0.57 – v0.0.58

Wraps a Vitest config to start the allwright engine once before the whole run and shut it down once after, instead of every test bootstrapping its own.

function allwrightVitestConfig<T extends UserConfig>(config: T): T

Example

import { allwrightVitestConfig } from "@allwright.dev/vitest/config";
export default allwrightVitestConfig(defineConfig({ test: {} }));