no-restricted-jest-methods
Configuration
rslint.config.ts
Rule Details
Disallow specific jest methods. Use this rule to ban particular jest.* calls that your team prefers to avoid, such as spies, mocks, or timer helpers, and optionally provide custom messages explaining the preferred alternative.
Restrictions are matched against the first member of a jest call chain. For example, banning fn reports jest.fn() and jest["fn"](), but not bare jest or jest() without a method name.
By default, no jest methods 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
jestmethod names and whose values are custom messages.- Keys are method names such as
fn,mock,spyOn, oradvanceTimersByTime. - Values are either a string (shown as the diagnostic message) or
null(uses the default message:Use of `{method}` is disallowed).
- Keys are method names such as
Examples of incorrect code with { "mock": "Do not use mocks" }:
Examples of incorrect code with { "fn": null }:
Examples of incorrect code with { "advanceTimersByTime": null }: