Chai Assertion Library

6.2.2 · active · verified Sat Apr 18

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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →