# Mocha Testing

> Mocha Testing

- Skill: `comeonoliver/mocha-testing` (Agent Skill)
- Install (CLI): `npx skillmds@latest add comeonoliver/mocha-testing`
- Raw SKILL.md: https://api.skillmd.com/api/skills/comeonoliver/mocha-testing/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ComeOnOliver (https://skillmd.com/u/comeonoliver)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/comeonoliver/mocha-testing

---

# Mocha Testing

## Setup
```bash
npm install -D mocha @types/mocha chai ts-node
```

## .mocharc.yml
```yaml
require: ts-node/register
spec: "test/**/*.test.ts"
timeout: 5000
recursive: true
```

## Tests
```typescript
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

