jest/prefer-to-have-length Style
What it does
In order to have a better failure message, toHaveLength() should be used upon asserting expectations on objects length property.
Why is this bad?
This rule triggers a warning if toBe(), toEqual() or toStrictEqual() is used to assert objects length property.
Examples
Examples of incorrect code for this rule:
javascript
expect(files["length"]).toBe(1);
expect(files["length"]).toBe(1);
expect(files["length"])["not"].toBe(1);Examples of correct code for this rule:
javascript
expect(files).toHaveLength(1);How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny jest/prefer-to-have-length --jest-pluginjson
{
"plugins": ["jest"],
"rules": {
"jest/prefer-to-have-length": "error"
}
}