jest/no-conditional-in-test
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-conditional-in-test": "error",
},
},
];it('foo', () => {
if (true) {
doTheThing();
}
});
it('bar', () => {
switch (mode) {
case 'none':
generateNone();
case 'single':
generateOne();
case 'multiple':
generateMany();
}
expect(fixtures.length).toBeGreaterThan(-1);
});
it('qux', async () => {
const promiseValue = () => {
return something instanceof Promise
? something
: Promise.resolve(something);
};
await expect(promiseValue()).resolves.toBe(1);
});describe('my tests', () => {
if (true) {
it('foo', () => {
doTheThing();
});
}
});
beforeEach(() => {
switch (mode) {
case 'none':
generateNone();
case 'single':
generateOne();
case 'multiple':
generateMany();
}
});
it('bar', () => {
expect(fixtures.length).toBeGreaterThan(-1);
});
const promiseValue = something => {
return something instanceof Promise ? something : Promise.resolve(something);
};
it('qux', async () => {
await expect(promiseValue()).resolves.toBe(1);
});Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jest/no-conditional-in-test
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-conditional-in-test": "error",
},
},
];jest/no-conditional-in-test
jest plugin · pedantic
{
"plugins": [
"jest"
],
"rules": {
"jest/no-conditional-in-test": "error"
}
}Biome does not have this rule.
Enforces a maximum number assertion calls in a test body
Disallow confusing usages of jest.setTimeout