Mocha
ELI5 — The Vibe Check
Mocha is an older, flexible JavaScript test runner that lets you pick your own assertion library and mocking tools. It's like a buffet — Mocha provides the plates, and you bring your own food (Chai for assertions, Sinon for mocks). More setup, more control.
Real Talk
Mocha is a flexible JavaScript test framework for Node.js that provides describe/it blocks and lifecycle hooks (before, after, beforeEach, afterEach). Unlike Jest, it doesn't include assertions or mocking — you combine it with Chai and Sinon.
Show Me The Code
const { expect } = require('chai');
describe('Calculator', () => {
it('should add two numbers', () => {
expect(add(2, 3)).to.equal(5);
});
});
When You'll Hear This
"This project uses Mocha + Chai — don't use Jest matchers here." / "Mocha is more flexible but Jest is simpler to set up."
Related Terms
Chai
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.
Jest
Jest is the most popular JavaScript testing framework.
Test Runner
A test runner is the thing that actually runs your tests and tells you which ones passed and which ones failed.
Vitest
Vitest is a blazing-fast test runner built on Vite. If Jest is the reliable sedan, Vitest is the electric sports car — same driving experience, 10x faster.