Skip to content

Chai

Medium — good to knowTesting

ELI5 — The Vibe Check

Chai is an assertion library that makes your test checks read like English. Instead of assert.equal(x, 5) you can write expect(x).to.equal(5) or even x.should.equal(5). It's grammar school for your tests — everything sounds more natural.

Real Talk

Chai is a BDD/TDD assertion library for Node.js and browsers, commonly paired with Mocha. It provides three assertion styles: assert (classical), expect (BDD chainable), and should (extends objects). Chai plugins extend it with additional matchers.

Show Me The Code

const { expect } = require('chai');

expect([1, 2, 3]).to.have.lengthOf(3);
expect('hello').to.be.a('string');
expect({ name: 'Alice' }).to.deep.equal({ name: 'Alice' });
expect(fn).to.throw(TypeError);

When You'll Hear This

"Use Chai's deep.equal for comparing objects in Mocha tests." / "Chai makes assertions read almost like natural language."

Made with passive-aggressive love by manoga.digital. Powered by Claude.