Use when a JavaScript or TypeScript suite still depends on Mocha, Chai, or Sinon and needs an incremental Jest migration.
How this skill is triggered — by the user, by Claude, or both
Slash command
/mocha-to-jest-migration:mocha-to-jest-migrationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- The suite still uses Mocha, Chai, or Sinon and needs a staged migration to Jest.
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.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub matt-riley/lucky-hat --plugin mocha-to-jest-migration