Skip to content

jest/prefer-equality-matcher Style

What it does

Jest has built-in matchers for expecting equality, which allow for more readable tests and error messages if an expectation fails.

Example

javascript
// invalid
expect(x === 5).toBe(true);
expect(name === "Carl").not.toEqual(true);
expect(myObj !== thatObj).toStrictEqual(true);

// valid
expect(x).toBe(5);
expect(name).not.toEqual("Carl");
expect(myObj).toStrictEqual(thatObj);

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny jest/prefer-equality-matcher --jest-plugin
json
{
  "plugins": ["jest"],
  "rules": {
    "jest/prefer-equality-matcher": "error"
  }
}

References

Released under the MIT License.