jest/no-restricted-jest-methods Style
What it does
Restrict the use of specific jest and vi methods.
Why is this bad?
Certain Jest methods may be deprecated, discouraged in specific contexts, or incompatible with your testing environment. Restricting them helps maintain consistent and reliable test practices.
Examples
Examples of incorrect code for this rule:
javascript
jest.useFakeTimers();
it("calls the callback after 1 second via advanceTimersByTime", () => {
// ...
jest.advanceTimersByTime(1000);
// ...
});
test("plays video", () => {
const spy = jest.spyOn(video, "play");
// ...
});Configuration
This rule accepts a configuration object with the following properties:
restrictedJestMethods
type: Record<string, string>
default: {}
A mapping of restricted Jest method names to custom messages.
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny jest/no-restricted-jest-methods --jest-pluginjson
{
"plugins": ["jest"],
"rules": {
"jest/no-restricted-jest-methods": "error"
}
}