jest/valid-expect
eslint-plugin-jest
Safe autofixRecommended
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/valid-expect": "error",
},
},
];// alwaysAwait: true
test('test1', async () => {
await expect(Promise.resolve(2)).resolves.toBeDefined();
return expect(Promise.resolve(1)).resolves.toBe(1); // `return` statement will trigger a warning
});// alwaysAwait: true
test('test1', async () => {
await expect(Promise.resolve(2)).resolves.toBeDefined();
await expect(Promise.resolve(1)).resolves.toBe(1);
});
test('test2', () => expect(Promise.resolve(2)).resolves.toBe(2));Examples from the ESLint documentation.
jest/valid-expect
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/valid-expect": "error",
},
},
];jest/valid-expect
jest plugin · correctness
{
"plugins": [
"jest"
],
"rules": {
"jest/valid-expect": "error"
}
}Biome does not have this rule.
Enforce assertion to be made in a test body
Disallow calling expect conditionally
Disallow using a callback in asynchronous tests and hooks