dánwòdánwò

Test API

expect

Assertions on locators and pages that wait until they hold or time out.

tests/checkout.danwo.ts
await expect(screen.getByTestId("checkout-total")).toContainText("$5.00")
await expect(screen.getByRole("heading", { name: "Thank you" })).toBeVisible()

expect(locator) and expect(screen) retry until their timeout; expect(value) is a plain value check.

Expect

interface

expect(locator) waits for the page; expect(screen) checks the page; expect(value) a value. A value's check takes a message too, printed with its failure, as in vitest.

MemberDescription
(actual: Locator): LocatorAssertions
(actual: Screen): PageAssertions
<T>(actual: T, message?: string): Assertion<void, T>

LocatorAssertions

interface

What expect(locator) offers.

MemberDescription
not: LocatorAssertionsThe same checks, each holding when the plain one would not.
toBeVisible: StateCheck
toBeHidden: StateCheck
toBeEnabled: StateCheck
toBeDisabled: StateCheck
toBeChecked: StateCheck
toBeInViewport: StateCheckSome of the element is inside the viewport as the page is scrolled now.
toHaveText: ValueCheck<TextMatch>The whole text, whitespace collapsed; a RegExp tests it.
toContainText: ValueCheck<TextMatch>
toHaveValue: ValueCheck<TextMatch>
toHaveCount: ValueCheck<number>
toHaveAttribute(name: string, value?: TextMatch, options?: AssertOptions): Promise<void>The attribute is present, and equals value when one is given.
toHaveCSS(property: string, value: TextMatch, options?: AssertOptions): Promise<void>The computed style's property ("color", "display") equals value, as the browser writes it.
toHaveJSProperty(name: string, value: unknown, options?: AssertOptions): Promise<void>The DOM element's JavaScript property name ("checked", "value", "dataset") equals value: compared deeply, so an object or array matches one with the same contents.
toHaveScreenshot(name?: string, options?: VisualOptions): Promise<void>The element looks like its baseline image (__screenshots__/ next to the test), written on the first run. name defaults to a number in order of the checks.

PageAssertions

interface

What expect(screen) offers: checks of the whole page.

MemberDescription
toHaveScreenshot(name?: string, options?: VisualOptions): Promise<void>The visible page looks like its baseline image; see the locator check of the same name.

VisualOptions

interface

extends ScreenshotOptions

Options of toHaveScreenshot: how strict, and which elements to paint over.

MemberDescription
mask?: readonly Locator[]Elements whose content changes from run to run (times, avatars), painted over in both.

On this page

Run it on every pull request

A GitHub check and one comment per pull request, with the flight records attached.

Set up CI