jest/no-restricted-matchers
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-restricted-matchers": "error",
},
},
];it('is false', () => {
// if this has a modifier (i.e. `not.toBeFalsy`), it would be considered fine
expect(a).toBeFalsy();
});
it('resolves', async () => {
// all uses of this modifier are disallowed, regardless of matcher
await expect(myPromise()).resolves.toBe(true);
});
describe('when an error happens', () => {
it('does not upload the file', async () => {
// all uses of this matcher are disallowed
expect(uploadFileMock).not.toHaveBeenCalledWith('file.name');
});
});The documentation shows no correct example for this rule.
Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jest/no-restricted-matchers
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-restricted-matchers": "error",
},
},
];jest/no-restricted-matchers
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/no-restricted-matchers": "error"
}
}Biome does not have this rule.
Disallow unnecessary async function wrapper for expected promises
Disallow using jest.mock() factories without an explicit type parameter
Disallow confusing usages of jest.setTimeout