Skip to content

jest/prefer-strict-equal Style

🛠️ An auto-fix is available for this rule.

What it does

This rule triggers a warning if toEqual() is used to assert equality.

Why is this bad?

The toEqual() matcher performs a deep equality check but ignores undefined values in objects and arrays. This can lead to false positives where tests pass when they should fail. toStrictEqual() provides more accurate comparison by checking for undefined values.

Examples

Examples of incorrect code for this rule:

javascript
expect({ a: "a", b: undefined }).toEqual({ a: "a" });

Examples of correct code for this rule:

javascript
expect({ a: "a", b: undefined }).toStrictEqual({ a: "a" });

How to use

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

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

References

Released under the MIT License.