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 install -D chai
yarn add -D chai
pnpm add -D chai
Import
import { expect } from 'chai';Quick Example
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
| Package | chai |
| Category | Testing |
| Weekly Downloads | 10M+ |
| License | MIT |
| Install | npm install -D chai |
Related Packages
Mocha is a feature-rich JavaScript test framework that runs on Node.js and in the browser, providing…
Sinon.js provides standalone test spies, stubs, and mocks for JavaScript that work with any test fra…
Jest is a delightful JavaScript testing framework with a focus on simplicity, created by Facebook. I…
SuperTest is a high-level HTTP assertion library built on SuperAgent that makes it easy to test Node…
Nock is an HTTP server mocking and expectations library for Node.js that intercepts outgoing HTTP re…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.