> Mocha Test Framework

JavaScript/TypeScript testing with Mocha. BDD/TDD style describe/it blocks, hooks, and async tests.

fetch
$curl "https://skillshub.wtf/skillshub-team/catalog-batch5/mocha-testing?format=md"
SKILL.mdMocha Test Framework

Mocha Testing

Setup

npm install -D mocha @types/mocha chai ts-node

.mocharc.yml

require: ts-node/register
spec: "test/**/*.test.ts"
timeout: 5000
recursive: true

Tests

import { expect } from 'chai';

describe('Calculator', () => {
    let calc: Calculator;
    beforeEach(() => { calc = new Calculator(); });

    it('should add numbers', () => { expect(calc.add(2, 3)).to.equal(5); });
    it('should throw on div by zero', () => {
        expect(() => calc.divide(1, 0)).to.throw('Division by zero');
    });
});

describe('API', () => {
    it('should fetch data', async () => {
        const data = await api.get('/users');
        expect(data).to.be.an('array');
    });
});

Hooks: before, after, beforeEach, afterEach

Run: npx mocha / npx mocha --grep "pattern" / npx mocha --watch

┌ stats

installs/wk0
░░░░░░░░░░
first seenMar 18, 2026
└────────────

┌ tags

└────────────