📝 Require that resolve and reject modifiers are present (and only) for
promise-like types.
💭 This rule requires type information.
When working with promises, you must remember to use resolves and rejects to
assert on the value returned (or thrown) by the promise, rather than the promise
itself.
Inversely, while Jest does not prevent you from using resolves and rejects
on non-promise values, it is not necessary.
When TypeScript is in use, it is possible to determine when resolves and
rejects should and should not be needed.
This rule warns when:
- an
expectis given a promise-like value but withoutresolvesorrejects - an
expectis not given a promise-like value, but is used withresolvesorrejects
The following patterns are considered warnings:
expect('hello world').resolves.toBe('hello sunshine');
expect(new Promise(r => r(0))).toThrow('oh noes!');The following patterns are not considered warnings:
expect('hello world').toBe('hello sunshine');
expect(new Promise(r => r(0))).rejects.toThrow('oh noes!');