jest/prefer-comparison-matcher
eslint-plugin-jest
Safe autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-comparison-matcher": "error",
},
},
];expect(x > 5).toBe(true);
expect(x < 7).not.toEqual(true);
expect(x <= y).toStrictEqual(true);expect(x).toBeGreaterThan(5);
expect(x).not.toBeLessThanOrEqual(7);
expect(x).toBeLessThanOrEqual(y);
// special case - see below
expect(x < 'Carl').toBe(true);expect(myName).toBeGreaterThanOrEqual(theirName); // Matcher error: received value must be a number or bigint// eslint-disable-next-line jest/prefer-comparison-matcher
expect(myName > theirName).toBe(true);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/prefer-comparison-matcher
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-comparison-matcher": "error",
},
},
];jest/prefer-comparison-matcher
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/prefer-comparison-matcher": "error"
}
}Biome does not have this rule.
Enforce using the built-in comparison matchers
Enforce padding around test and it blocks
Prefer having the last statement in a test be an assertion
Enforce padding around describe blocks