with one click
mocha-to-jest-migration
Use when a JavaScript or TypeScript suite still depends on Mocha, Chai, or Sinon and needs an incremental Jest migration.
Menu
Use when a JavaScript or TypeScript suite still depends on Mocha, Chai, or Sinon and needs an incremental Jest migration.
Use when auditing JS/TS code health with Fallow - dead code, duplication, boundaries, or cleanup; not for debugging failures.
Use when a JavaScript or TypeScript project needs Knip to find unused dependencies, exports, files, or unresolved imports; not for runtime failures or dormant-task recovery.
Use when creating or revising a reusable agent skill under skills/<name>/SKILL.md — deciding activation, layering, examples, or validation, or choosing between a skill vs. instructions vs. a specialized agent.
Run, debug, and extend tests for Go projects, including generation prerequisites. Use when domain logic, repositories, HTTP handlers, migrations, or unexpected test failures need coverage.
Draft structured documents, audit prose readability, and review short audience-facing metadata strings. Use when the primary work is writing, editing, or copy quality.
Use when user wants to write, refactor, or expand documentation (README, guides, API docs, runbooks, specification documents).
| name | mocha-to-jest-migration |
| description | Use when a JavaScript or TypeScript suite still depends on Mocha, Chai, or Sinon and needs an incremental Jest migration. |
| metadata | {"category":"migrations","audience":"general-coding-agent","maturity":"beta"} |
describe/it tests using Chai assertions or Sinon stubs that need Jest equivalents.Required before editing
Helpful if present
Only investigate if encountered
chai-as-promised, chai-http) that need separate handling.Inventory what needs to migrate before touching any test files:
grep -r "require('chai')\|from 'chai'\|require('sinon')\|from 'sinon'" --include="*.ts" --include="*.js" -l
grep -r "require('mocha')\|\.mocharc" --include="*.ts" --include="*.js" --include="*.json" -l
Then convert a single small representative file first, run it under Jest, and confirm the project's Jest setup works before migrating more files.
Consult references/assertion-mapping.md and references/mock-mapping.md before rewriting patterns.
before/after → beforeAll/afterAll, beforeEach/afterEach stay the same).Use this as the shape for one end-to-end file before scaling out:
// Mocha + Chai + Sinon
describe("retries", () => {
let clock;
beforeEach(() => {
clock = sinon.useFakeTimers();
});
afterEach(() => {
clock.restore();
sinon.restore();
});
it("waits and retries once", async () => {
const request = sinon.stub(api, "request").rejects(new Error("nope"));
const retry = sinon.stub(api, "retry").resolves({ ok: true });
const run = service.run();
await clock.tickAsync(1000);
await run;
expect(request.calledOnce).to.equal(true);
expect(retry.calledOnce).to.equal(true);
expect(retry.firstCall.args[0]).to.deep.equal({ delay: 1000 });
});
});
// Jest
describe("retries", () => {
beforeEach(() => {
jest.useFakeTimers();
jest.spyOn(api, "request").mockRejectedValue(new Error("nope"));
jest.spyOn(api, "retry").mockResolvedValue({ ok: true });
});
afterEach(() => {
jest.useRealTimers();
jest.restoreAllMocks();
});
it("waits and retries once", async () => {
const run = service.run();
await jest.advanceTimersByTimeAsync(1000);
await run;
expect(api.request).toHaveBeenCalledTimes(1);
expect(api.retry).toHaveBeenCalledTimes(1);
expect(api.retry).toHaveBeenCalledWith({ delay: 1000 });
});
});
Run the migrated Jest tests after each batch using the repository's existing commands.
Confirm fake timers, async failures, setup hooks, and mock reset behavior still match intent.
Check CI behavior if the migration changes test environment defaults or coverage collection.
Smoke test:
test-driven-development)user.spec.ts from sinon.stub(api, 'fetch') and expect(value).to.equal(...) to jest.spyOn(api, 'fetch') and expect(value).toBe(...)."references/assertion-mapping.md — Chai BDD and assert-style assertions mapped to Jest matchers.references/mock-mapping.md — Sinon spies, stubs, mocks, fake timers, and sandbox patterns mapped to Jest equivalents.