jest/valid-expect Correctness ​
What it does ​
Checks that expect()
is called correctly.
Why is this bad?
expect()
is a function that is used to assert values in tests. It should be called with a single argument, which is the value to be tested. If you call expect()
with no arguments, or with more than one argument, it will not work as expected.
Example ​
Examples of incorrect code for this rule:
javascript
expect();
expect("something");
expect(true).toBeDefined;
expect(Promise.resolve("Hi!")).resolves.toBe("Hi!");
Examples of correct code for this rule:
javascript
expect("something").toEqual("something");
expect(true).toBeDefined();
expect(Promise.resolve("Hi!")).resolves.toBe("Hi!");
This rule is compatible with eslint-plugin-vitest, to use it, add the following configuration to your .eslintrc.json
:
json
{
"rules": {
"vitest/valid-expect": "error"
}
}
How to use ​
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny jest/valid-expect --jest-plugin
json
{
"plugins": ["jest"],
"rules": {
"jest/valid-expect": "error"
}
}