jest/valid-expect-with-promise
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/valid-expect-with-promise": "error",
},
},
];Require that resolve and reject modifiers are present (and only) for promise-like types
expect('hello world').resolves.toBe('hello sunshine');
expect(new Promise(r => r(0))).toThrow('oh noes!');expect('hello world').toBe('hello sunshine');
expect(new Promise(r => r(0))).rejects.toThrow('oh noes!');declare function createPromiseLike(): PromiseLike<string>;
await expect(createPromiseLike()).resolves.toBe('hello sunshine');
interface MyThenable {
then(onFulfilled: () => void, onRejected: () => void): MyThenable;
}
declare function createMyThenable(): MyThenable;
await expect(createMyThenable()).resolves.toBe('hello sunshine');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/valid-expect-with-promise
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/valid-expect-with-promise": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Enforce unbound methods are called with their expected scope