jest/valid-describe-callback Correctness
What it does
This rule validates that the second parameter of a describe() function is a callback function. This callback function:
- should not be async
- should not contain any parameters
- should not contain any
returnstatements
Why is this bad?
Using an improper describe() callback function can lead to unexpected test errors.
Examples
Examples of incorrect code for this rule:
javascript
// Async callback functions are not allowed
describe("myFunction()", async () => {
// ...
});
// Callback function parameters are not allowed
describe("myFunction()", done => {
// ...
});
// Returning a value from a describe block is not allowed
describe("myFunction", () =>
it("returns a truthy value", () => {
expect(myFunction()).toBeTruthy();
}));This rule is compatible with eslint-plugin-vitest, to use it, add the following configuration to your .eslintrc.json:
json
{
"rules": {
"vitest/valid-describe-callback": "error"
}
}How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny jest/valid-describe-callback --jest-pluginjson
{
"plugins": ["jest"],
"rules": {
"jest/valid-describe-callback": "error"
}
}