Eslint rules for Jest Extended
npm install eslint-plugin-jest-extended
```
$ yarn add --dev eslint eslint-plugin-jest-extended
Note: If you installed ESLint globally then you must also install
eslint-plugin-jest-extended globally.
> [!NOTE]
>
> eslint.config.js is supported, though most of the plugin documentation still.eslintrc
> currently uses syntax.
>
> Refer to the
> ESLint documentation on the new configuration file format
> for more.
Add jest-extended to the plugins section of your .eslintrc configurationeslint-plugin-
file. You can omit the prefix:
`json`
{
"plugins": ["jest-extended"]
}
Then configure the rules you want to use under the rules section.
`json`
{
"rules": {
"jest-extended/prefer-to-be-true": "warn",
"jest-extended/prefer-to-be-false": "error"
}
}
This plugin does not export a recommended configuration, as the rules provided
by this plugin are about enforcing usage of preferred matchers for particular
patterns, rather than helping to prevent bugs & commonly overlooked traps.
If you want to enable all rules instead of only some you can do so by adding the
all configuration to your .eslintrc config file:
`json`
{
"extends": ["plugin:jest-extended/all"]
}
To enable this configuration with eslint.config.js, usejestExtended.configs['flat/all']:
`js
const jestExtended = require('eslint-plugin-jest-extended');
module.exports = [
{
files: [
/ glob matching your test files /
],
...jestExtended.configs['flat/all'],
},
];
`
Note that the all configuration may change in any release and is thus unsuited
for installations requiring long-term consistency.
š§ Automatically fixable by the
--fix CLI option.
| Name | Description | š§ |
| :------------------------------------------------------------------------------- | :------------------------------------- | :-- |
| prefer-to-be-array | Suggest using toBeArray() | š§ |toBeFalse()
| prefer-to-be-false | Suggest using | š§ |toBeObject()
| prefer-to-be-object | Suggest using | š§ |toBeTrue()
| prefer-to-be-true | Suggest using | š§ |toHaveBeenCalledOnce()` | š§ |
| prefer-to-have-been-called-once | Suggest using
This project aims to provide linting rules to aid in writing tests using jest.
https://github.com/jest-community/eslint-plugin-jest
This project aims to provide formatting rules (auto-fixable where possible) to
ensure consistency and readability in jest test suites.
https://github.com/dangreenisrael/eslint-plugin-jest-formatting
[fixable]: https://img.shields.io/badge/-fixable-green.svg