jest/no-standalone-expect Correctness ​
What it does ​
Prevents expect statements outside of a test or it block. An expect within a helper function (but outside of a test or it block) will not trigger this rule.
Statements like expect.hasAssertions() will NOT trigger this rule since these calls will execute if they are not in a test block.
Why is this bad? ​
expect statements outside of test blocks will not be executed by the Jest test runner, which means they won't actually test anything. This can lead to false confidence in test coverage and may hide bugs that would otherwise be caught by proper testing.
Examples ​
Examples of incorrect code for this rule:
describe("a test", () => {
expect(1).toBe(1);
});Configuration ​
This rule accepts a configuration object with the following properties:
additionalTestBlockFunctions ​
type: string[]
default: []
An array of function names that should also be treated as test blocks.
How to use ​
To enable this rule in the CLI or using the config file, you can use:
oxlint --deny jest/no-standalone-expect --jest-plugin{
"plugins": ["jest"],
"rules": {
"jest/no-standalone-expect": "error"
}
}