ESLint plugin that checks for common chai.js expect() mistakes
[!IMPORTANT] The
recommendedpreset is for the ESLint legacy configuration system (.eslintrc.json). Therecommended-flatconfiguration is for the new flat configuration system.
npm install --save-dev eslint-plugin-chai-expect
Add a plugins section and specify chai-expect as a plugin:
{
"plugins": [
"chai-expect"
]
}
Enable the rules that you would like to use:
{
"rules": {
"chai-expect/no-inner-compare": 2,
"chai-expect/no-inner-literal": 2,
"chai-expect/missing-assertion": 2,
"chai-expect/terminating-properties": 2
}
}
Or, if you just want the above defaults, you can avoid all of the above and just extend the config:
{
"extends": ["plugin:chai-expect/recommended"]
}
Add a plugins section and specify chai-expect as a plugin and enable the rules that you would like to use:
import chaiExpectPlugin from 'eslint-plugin-chai-expect';
export default [
{
"plugins": {
"chai-expect": chaiExpectPlugin
},
"rules": {
"chai-expect/no-inner-compare": 2,
"chai-expect/no-inner-literal": 2,
"chai-expect/missing-assertion": 2,
"chai-expect/terminating-properties": 2,
"chai-expect/no-uncalled-method": 2
}
}
];
Or, if you just want the above defaults, you can avoid all of the above and just extend the config:
import chaiExpectPlugin from 'eslint-plugin-chai-expect';
export default [
chaiExpectPlugin.configs["recommended-flat"],
{
// ...
},
];
no-inner-compare - Prevent using comparisons in the expect() argumentno-inner-literal - Prevent using literals in the expect() argument
(undefined, null, NaN, (+|-)Infinity, this, booleans, numbers,
strings, and BigInt or regex literals)missing-assertion - Prevent calling expect(...) without an assertion
like .to.be.okterminating-properties - Prevent calling to.be.ok and other assertion
properties as functionsno-uncalled-method - Prevent using to.throw and other assertion
methods as properties without calling themA number of extensions to chai add additional terminating properties. For example chai-http adds:
The terminating-properties rule can be configured to ensure these (or other) additional properties are not used as functions:
{
"rules": {
"chai-expect/terminating-properties": ["error", {
"properties": ["headers", "html", "ip", "json", "redirect", "test"]
}]
}
}
By default, this rule checks for throw, throws, and Throw. You can configure additional methods that should not be used as properties:
{
"rules": {
"chai-expect/no-uncalled-method": ["error", {
"methods": ["include", "satisfy", "respondTo"]
}]
}
}
eslint-plugin-chai-expect is licensed under the MIT License.
JavaScript
100.0%
ESLint plugin that checks for common chai.js expect() mistakes
[!IMPORTANT] The
recommendedpreset is for the ESLint legacy configuration system (.eslintrc.json). Therecommended-flatconfiguration is for the new flat configuration system.
npm install --save-dev eslint-plugin-chai-expect
Add a plugins section and specify chai-expect as a plugin:
{
"plugins": [
"chai-expect"
]
}
Enable the rules that you would like to use:
{
"rules": {
"chai-expect/no-inner-compare": 2,
"chai-expect/no-inner-literal": 2,
"chai-expect/missing-assertion": 2,
"chai-expect/terminating-properties": 2
}
}
Or, if you just want the above defaults, you can avoid all of the above and just extend the config:
{
"extends": ["plugin:chai-expect/recommended"]
}
Add a plugins section and specify chai-expect as a plugin and enable the rules that you would like to use:
import chaiExpectPlugin from 'eslint-plugin-chai-expect';
export default [
{
"plugins": {
"chai-expect": chaiExpectPlugin
},
"rules": {
"chai-expect/no-inner-compare": 2,
"chai-expect/no-inner-literal": 2,
"chai-expect/missing-assertion": 2,
"chai-expect/terminating-properties": 2,
"chai-expect/no-uncalled-method": 2
}
}
];
Or, if you just want the above defaults, you can avoid all of the above and just extend the config:
import chaiExpectPlugin from 'eslint-plugin-chai-expect';
export default [
chaiExpectPlugin.configs["recommended-flat"],
{
// ...
},
];
no-inner-compare - Prevent using comparisons in the expect() argumentno-inner-literal - Prevent using literals in the expect() argument
(undefined, null, NaN, (+|-)Infinity, this, booleans, numbers,
strings, and BigInt or regex literals)missing-assertion - Prevent calling expect(...) without an assertion
like .to.be.okterminating-properties - Prevent calling to.be.ok and other assertion
properties as functionsno-uncalled-method - Prevent using to.throw and other assertion
methods as properties without calling themA number of extensions to chai add additional terminating properties. For example chai-http adds:
The terminating-properties rule can be configured to ensure these (or other) additional properties are not used as functions:
{
"rules": {
"chai-expect/terminating-properties": ["error", {
"properties": ["headers", "html", "ip", "json", "redirect", "test"]
}]
}
}
By default, this rule checks for throw, throws, and Throw. You can configure additional methods that should not be used as properties:
{
"rules": {
"chai-expect/no-uncalled-method": ["error", {
"methods": ["include", "satisfy", "respondTo"]
}]
}
}
eslint-plugin-chai-expect is licensed under the MIT License.
JavaScript
100.0%