🧪
Testing10M+/wkMIT

chai

Chai is a BDD/TDD assertion library for Node.js and the browser that pairs with any JavaScript testing framework. Chai provides three assertion styles to match

Installation

npm
npm install -D chai
yarn
yarn add -D chai
pnpm
pnpm add -D chai

Import

ESM
import { expect } from 'chai';

Quick Example

usage
import { expect } from 'chai';

expect('hello').to.be.a('string');
expect([1, 2, 3]).to.have.lengthOf(3);
expect({ a: 1 }).to.deep.equal({ a: 1 });
expect(() => { throw new Error('fail'); }).to.throw('fail');

About chai

Chai is a BDD/TDD assertion library for Node.js and the browser that pairs with any JavaScript testing framework. Chai provides three assertion styles to match different coding preferences: expect (BDD fluent chains like expect(foo).to.be.a('string')), should (BDD property access like foo.should.be.a('string')), and assert (TDD classical like assert.typeOf(foo, 'string')). The expect and should interfaces provide expressive, readable assertions through chainable language chains including .to, .be, .been, .is, .that, .which, .and, .has, .have, .with, .at, .of, and .same. Built-in assertions cover deep equality, type checking, property existence, string inclusion, array membership, regular expression matching, error throwing, and numeric comparisons with .above, .below, .within, and .closeTo. Chai's plugin system extends the assertion vocabulary — popular plugins include chai-as-promised for promise assertions, chai-http for HTTP response testing, chai-things for array element assertions, and sinon-chai for Sinon.js integration. Chai is most commonly paired with Mocha but works equally well with any test runner that surfaces assertion errors.

Quick Facts

Packagechai
CategoryTesting
Weekly Downloads10M+
LicenseMIT
Installnpm install -D chai

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.