valid-expect
Configuration
Rule Details
Enforce valid expect() usage in Jest tests. This rule ensures that every
expect() call has the expected number of arguments, ends with a matcher that
is actually invoked, uses only supported modifiers (.not, .resolves,
.rejects), and that async assertions are properly awaited or returned.
The rule is fixable: when an async assertion appears inside a function, rslint
can insert async on the enclosing function and await on the assertion.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
-
alwaysAwait(default:false): Whentrue, onlyawaitis accepted for async assertions inside block statements.return expect(...).resolves...is reported. One-line arrow functions with an implicit return remain valid. -
asyncMatchers(default:["toResolve", "toReject"]): Matcher names that should be treated as async even without.resolvesor.rejects. Use this for custom matchers from libraries such asjest-extended. -
minArgs(default:1): Minimum number of arguments allowed inexpect(). Set to0when using libraries such asjest-expect-message. -
maxArgs(default:1): Maximum number of arguments allowed inexpect().
Examples of incorrect code for { "alwaysAwait": true }:
Examples of correct code for { "alwaysAwait": true }:
Examples of correct code for { "minArgs": 0 }: