1. eslint-plugin-chai-expect
ESLint plugin that checks for common chai.js expect() mistakes
eslint-plugin-chai-expect
Package: eslint-plugin-chai-expect
Created by: turbo87
Last modified: Fri, 17 Jun 2022 20:28:04 GMT
Version: 3.0.0
License: MIT
Downloads: 243,247
Repository: https://github.com/turbo87/eslint-plugin-chai-expect

Install

npm install eslint-plugin-chai-expect
yarn add eslint-plugin-chai-expect

eslint-plugin-chai-expect

Build Status

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

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

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

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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code