You can disable the rule for the entire file using eslint-disable
at the top of the file in question:
/* eslint-disable no-unused-expressions */
expect(someTrueValue).to.be.true;
However, adding this at the top of every test file can be tedious. To disable this rule for all relevant files, you can:
-
Put a new
.eslintc
configuration file in the same directory as your test files, configured to disable that rule. This allows you to use the default configuration for all other rules while ignoring that rule specifically only on files in that folder. ESLint calls thisConfiguration Cascading
.{ "rules": { "no-unused-expressions": "off" } }
-
Use the
overrides
key in your main.eslintrc
file to disable rules for groups of files with glob pattern matching:{ "overrides": [ { "files": ["*.test.js", "*.spec.js"], "rules": { "no-unused-expressions": "off" } } ] }
This also allows you to disable other rules which become troublesome in testing, such as no-underscore-dangle
when using rewire
.