vitest/prefer-to-be-truthy Style
What it does
This rule warns when toBe(true) is used with expect or expectTypeOf. With --fix-suggestions, it will be replaced with toBeTruthy().
Why is this bad?
When testing for truthiness, toBeTruthy() expresses that intent directly. Unlike toBe(true), it also accepts non-boolean truthy values such as non-empty strings and objects. The replacement is a suggestion because it changes which values pass the assertion.
Examples
Examples of incorrect code for this rule:
javascript
expect(foo).toBe(true);
expectTypeOf(foo).toBe(true);Examples of correct code for this rule:
javascript
expect(foo).toBeTruthy();
expectTypeOf(foo).toBeTruthy();How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/prefer-to-be-truthy": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/prefer-to-be-truthy": "error",
},
});bash
oxlint --deny vitest/prefer-to-be-truthy --vitest-pluginVersion
This rule was added in v0.7.1.
