Registry / testing / chai
library1.1.2jsnpmunverified

Chai is a widely used BDD/TDD assertion library for both Node.js and browser environments, designed to be framework-agnostic and pair delightedly with any JavaScript testing framework. The current stable version is 6.2.2, with frequent patch and minor releases, alongside periodic major updates, demonstrating an active development cadence.

npm install chai
INSTALL
IMPORT
SIG · CHAI
C
chai
testingjavascriptv1.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

expect
import { expect } from 'chai';
const expect = require('chai').expect;
assert
import { assert } from 'chai';
const assert = require('chai').assert;
should
import { should } from 'chai'; should();
import { should } from 'chai';

This quickstart demonstrates basic assertions using Chai's Expect style, including numerical comparisons, boolean checks, and deep object equality.

import { expect } from 'chai'; const add = (a, b) => a + b; const isPositive = (num) => num > 0; // Basic assertions expect(add(2, 3)).to.equal(5); expect(add(-1, 5)).to.be.above(0); expect(isPositive(10)).to.be.true; // Deep equality for objects expect({ a: 1, b: 2 }).to.deep.equal({ a: 1, b: 2 });
Debug
Known issues
breakingChai v6.0.0 introduced a breaking change where direct imports from internal `lib/*.js` files are no longer supported. The library is now bundled into a single `index.js`.
fix
Update your imports to reference the main `chai` package directly, e.g., `import { expect } from 'chai';` instead of `import { expect } from 'chai/lib/expect';`.
affects: >=6.0.0
gotchaWhen using Chai's `should` assertion style, you must explicitly call `should()` after importing it to extend `Object.prototype` and enable the assertion syntax.
fix
After `import { should } from 'chai';`, add `should();` on the next line.
affects: >=1.0.0
gotchaImporting a Chai assertion style globally (e.g., `import 'chai/register-expect';`) modifies the global scope. While convenient for quick setups, this can lead to unexpected side effects or conflicts in larger projects.
fix
Prefer importing assertion styles locally (e.g., `import { expect } from 'chai';`) to avoid global pollution and ensure better test isolation.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chai/lib/expect' imported from ...
Attempting to import internal `lib/*.js` files directly after Chai v6.0.0, which bundled the library into a single `index.js`.
fix
Change the import path to `import { expect } from 'chai';` or `import { assert } from 'chai';`.
TypeError: (0 , chai__WEBPACK_IMPORTED_MODULE_0__.should) is not a function
Using Chai's `should` assertion style without calling `should()` after importing it, which is necessary to extend `Object.prototype`.
fix
Add `should();` immediately after the import statement: `import { should } from 'chai'; should();`.
ReferenceError: require is not defined
Attempting to use the CommonJS `require` function in an ECMAScript Module (ESM) file context (e.g., a `.mjs` file or a project with `"type": "module"` in `package.json`).
fix
Update your code to use ESM `import` statements, for example, `import { expect } from 'chai';` instead of `const expect = require('chai').expect;`.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
chai — npm install chai · libregistry