no-restricted-matchers
Configuration
Rule Details
Disallow specific Jest matchers and modifiers in expect() chains. Use this rule to ban matchers or modifiers that your team prefers to avoid, and optionally suggest alternatives via custom messages.
Restrictions are matched against the start of an expect() chain. For example, banning not reports any chain that begins with .not, while banning not.toBe only reports that specific prefix. To ban a matcher in every form (with or without .not, .resolves, or .rejects), list each permutation you want to disallow.
By default, no matchers or modifiers are restricted.
Examples of incorrect code for this rule with the following configuration:
Options
- First argument (required to enable the rule): object whose keys are restricted matcher chains and whose values are custom messages.
- Keys are dot-separated chains such as
toBe,not.toBe,resolves.toBe, orresolves.not.toBe. - Values are either a string (shown as the diagnostic message) or
null(uses the default message:Use of `{chain}` is restricted).
- Keys are dot-separated chains such as
Examples of incorrect code with { "toBe": "Prefer toStrictEqual instead" }:
Examples of incorrect code with { "not.toBe": null }:
Examples of correct code with { "not.toBe": null }: