valid-expect-with-promise
Added in v0.9.4Configuration
Rule Details
Require that resolves and rejects modifiers are present (and only) for promise-like types.
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.
This rule requires type information and reports when:
- an
expectis given a promise-like value but withoutresolvesorrejects - an
expectis not given a promise-like value, but is used withresolvesorrejects
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
- First argument (optional): object with
checkThenablescheckThenables: also treat values whosethenmethod accepts both a fulfillment and a rejection callback as promises, not justPromiseitself. Default isfalse.
A thenable is an object with a then method, such as a Promise, TypeScript's built-in PromiseLike interface, or any custom object that has a .then(). This option is useful when working with older Promise polyfills instead of the native Promise class, or when the global Promise is not declared by TypeScript's default libraries.
Examples of incorrect code with { "checkThenables": true }:
Examples of correct code with { "checkThenables": true }: