Pular para o conteúdo

useExpect

Este conteúdo não está disponível em sua língua ainda.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useExpect": "error"
}
}
}
}

Ensure that test functions contain at least one expect() assertion.

Tests without assertions may pass even when behavior is broken, leading to false confidence in the test suite. This rule ensures that every test validates some expected behavior using expect().

test("no assertion", async ({ page }) => {
await page.goto("/");
await page.click("button");
});
code-block.js:1:1 lint/nursery/useExpect ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Test callback is missing an expect() assertion.

> 1 │ test(“no assertion”, async ({ page }) => {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ await page.goto(”/”);
> 3 │ await page.click(“button”);
> 4 │ });
^^
5 │

Tests without assertions may pass even when the behavior is broken.

Add an assertion using expect() to verify the expected behavior.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

test("has assertion", async ({ page }) => {
await page.goto("/");
await expect(page).toHaveTitle("Title");
});
test("soft assertion", async ({ page }) => {
await page.goto("/");
await expect.soft(page.locator("h1")).toBeVisible();
});