Chai
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."
Related Terms
Assertion
An assertion is your test saying 'I DEMAND this is true!'. It's you checking that the result is what you expected.
BDD (BDD)
BDD is like writing your tests in plain English so your non-coder boss can also understand them.
Jest
Jest is the most popular JavaScript testing framework.
Mocha
Mocha is an older, flexible JavaScript test runner that lets you pick your own assertion library and mocking tools.