jest/no-conditional-expect
eslint-plugin-jest
No autofixRecommended
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-conditional-expect": "error",
},
},
];test("conditional expect", async ({ page }) => {
if (someCondition) {
await expect(page).toHaveTitle("Title");
}
});test("ternary expect", async ({ page }) => {
someCondition ? await expect(page).toHaveTitle("Title") : null;
});test("catch expect", async ({ page }) => {
try {
await page.click("button");
} catch (e) {
await expect(page).toHaveTitle("Title");
}
});test("unconditional expect", async ({ page }) => {
await expect(page).toHaveTitle("Title");
});test("skip based on condition", async ({ page }) => {
test.skip(someCondition, "Reason to skip");
await expect(page).toHaveTitle("Title");
});Examples from the Biome documentation.
jest/no-conditional-expect
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-conditional-expect": "error",
},
},
];jest/no-conditional-expect
jest plugin · correctness
{
"plugins": [
"jest"
],
"rules": {
"jest/no-conditional-expect": "error"
}
}suspicious/noConditionalExpect
suspicious · since 2.4.2
{
"linter": {
"rules": {
"suspicious": {
"noConditionalExpect": "error"
}
}
}
}Enforce assertion to be made in a test body
Disallow using a callback in asynchronous tests and hooks
Disallow using expect outside of it or test blocks