Skip to content
← Back to rules

vitest/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 using the config file or in the CLI, you can use:

json
{
  "plugins": ["vitest"],
  "rules": {
    "vitest/prefer-strict-equal": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["vitest"],
  rules: {
    "vitest/prefer-strict-equal": "error",
  },
});
bash
oxlint --deny vitest/prefer-strict-equal --vitest-plugin

Version ​

This rule was added in v0.2.13.

References ​