Testing

test/web-first-assertions

Playwright tests assert with auto-retrying web-first matchers (toBeVisible, toHaveText), not on values read once.

moderatestaticfe-testing

Why

expect(await locator.isVisible()).toBe(true) reads the page once, at whatever moment the line runs. If the element appears 50 ms later the test fails, so it passes on a fast machine and flakes in CI.

Fix

Use the matcher that waits: await expect(locator).toBeVisible(), toHaveText, toHaveValue, toHaveAttribute, toHaveCount, toBeChecked, toHaveURL. Locate with user-facing locators (getByRole, getByLabel, getByText).

Examples

// bad
expect(await page.getByRole('status').isVisible()).toBe(true)
// good
await expect(page.getByRole('status')).toBeVisible()

Sources

Facts

Id
test/web-first-assertions
Severity
moderate
Check
static checked in the source by audit
Applies to
jsx
Only in projects with
playwright
Taught by the skill
fe-testing Front-end testing
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain test/web-first-assertions