-
Notifications
You must be signed in to change notification settings - Fork 241
Description
There's a conflict when using eslint-plugin-jest
's prefer-expect-assertions
rule alongside ESLint's core no-magic-numbers
rule. Here's a simple example:
test('some test', () => {
expect.assertions(1); // should NOT trigger no-magic-numbers
const result = someFunction(42); // SHOULD trigger no-magic-numbers
expect(true).toBeTruthy();
});
The call to expect.assertions(1)
is semantically meaningful and encouraged by prefer-expect-assertions
, yet it's flagged by no-magic-numbers
due to the numeric literal.
I raised this issue with the ESLint maintainers here: eslint/eslint#19956, but the response was:
As stated in the docs, this rule is currently frozen and is not accepting feature requests. You can always copy the rule source code into your custom rule and modify it to fit your needs.
Rather than creating a custom rule, and since I believe this conflict affects many others, it would be great if this functionality could be integrated into eslint-plugin-jest
, if feasible.
Possible Solutions
- Ignore magic numbers specifically inside
expect.assertions(<number>)
- Or, provide a config option like
ignoreAssertionCounts: true
This would maintain alignment between Jest best practices and ESLint rules without forcing unnecessary suppression or duplication.
Thanks for considering this!