Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-chai-expect

turbo87161.6kMIT3.1.0

ESLint plugin that checks for common chai.js expect() mistakes

chai, eslint, eslint-plugin, eslintplugin

readme

eslint-plugin-chai-expect

Build Status

ESLint plugin that checks for common chai.js expect() mistakes

[!IMPORTANT] The recommended preset is for the ESLint legacy configuration system (.eslintrc.json). The recommended-flat configuration is for the new flat configuration system.

Requirements

  • Node.js 6 or above
  • ESLint 4.x or 5.x or 6.x

Installation

npm install --save-dev eslint-plugin-chai-expect

Configuration

Legacy ESLint Configuration Format (.eslintrc.json)

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"]
}

Flat ESLint Configuration Format (eslint.config.js)

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
    }
  }
];

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"],
  {
    // ...
  },
];

Rules

  • no-inner-compare - Prevent using comparisons in the expect() argument
  • no-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.ok
  • terminating-properties - Prevent calling to.be.ok and other assertion properties as functions

Additional configuration

terminating-properties rule

A number of extensions to chai add additional terminating properties. For example chai-http adds:

  • headers
  • html
  • ip
  • json
  • redirect
  • text

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"]
    }]
  }
}

License

eslint-plugin-chai-expect is licensed under the MIT License.

changelog

Changelog

v3.1.0 (2024-06-13)

:rocket: Enhancement

:house: Internal

  • #391 Convert test suite to ESM (@Turbo87)
  • #390 ESLint: Migrate to flat config internally (@Turbo87)
  • #389 CI: Add ESLint 9 to test matrix (@Turbo87)
  • #388 Adjust test suite to be compatible with ESLint 9 (@Turbo87)
  • #386 Update gitignore from "Node" template (@Turbo87)
  • #381 Use current versions of github actions and node in github workflows and package.json (@BePo65)

Committers: 3

v3.0.0 (2021-10-20)

:boom: Breaking Change

:rocket: Enhancement

:house: Internal

Committers: 3

v2.2.0 (2020-07-08)

:rocket: Enhancement

  • #106 Add support for ESLint@7 as a peerDependency (@epmatsw)

:house: Internal

Committers: 3

v2.1.0 (2019-12-07)

:rocket: Enhancement

:bug: Bug Fix

  • #88 Allow terminating-properties with ReturnStatement (@brettz9)
  • #87 Allow return with no-inner-compare (@brettz9)

:memo: Documentation

:house: Internal

  • #85 Use ES6 template literals for multiline testing code (@brettz9)
  • #77 CI: Add ESLint 6 to test matrix (@brettz9)
  • #82 Use ES6 syntax features (@brettz9)
  • #83 npm: Add recommended package.json fields (contributors, dependencies) (@brettz9)

Committers: 1

v2.0.1 (2018-10-13)

:rocket: Enhancement

Committers: 1

v2.0.0 (2018-10-13)

:boom: Breaking Change

:rocket: Enhancement

:house: Internal

Committers: 1

v1.2.0 (2018-10-13)

:rocket: Enhancement

  • #19 Allow additional terminating properties to be configured (@whamondg)
  • #21 Test against eslint version 4 (@thughes)

:bug: Bug Fix

:memo: Documentation

  • #24 Document installation of this package as a devDependency (@astorije)
  • #23 Document terminating-properties rule (@whamondg)

:house: Internal

Committers: 5

v1.1.1

  • terminating-properties: Fix condition

v1.1.0

  • Add no-inner-compare rule
  • Add terminating-properties rule

v1.0.0

  • Add missing-assertion rule