Skip to content
Agentmart
Submit a tool

mocha-to-jest-migration

Use when a JavaScript or TypeScript suite still depends on Mocha, Chai, or Sinon and needs an incremental Jest migration.

Skill by matt-riley

IndexedGPL-3.0★ 4
Write a review

Chalk Labs

Need help deploying mocha-to-jest-migration?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/matt-riley-mocha-to-jest-migration

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use when a JavaScript or TypeScript suite still depends on Mocha, Chai, or Sinon and needs an incremental Jest migration.

Use cases: testing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Node.js package

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/mocha-to-jest-migration

What's inside

Skill 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.
License
GPL-3.0
Metadata
kind: task · version: 1.0.0 · audience: general-coding-agent · category: migrations · maturity: draft
Instructions
144 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Files (13)

  • .skill-eval.yaml
  • SKILL.md
  • evals.json · evals/
  • mixed-patterns.spec.js · evals/fixtures/
  • mock-lifecycle.spec.js · evals/fixtures/
  • proxyquire-module.spec.js · evals/fixtures/
  • sinon-args.spec.js · evals/fixtures/
  • sinon-sandbox.spec.js · evals/fixtures/
  • sinon-stubs.spec.js · evals/fixtures/
  • sinon-timers.spec.js · evals/fixtures/
  • trigger-queries.json · evals/
  • assertion-mapping.md · references/
  • mock-mapping.md · references/

SKILL.md (first lines)

# Mocha to Jest migration

## Use this skill when

- The suite still uses Mocha, Chai, or Sinon and needs a staged migration to Jest.
- You find `describe`/`it` tests using Chai assertions or Sinon stubs that need Jest equivalents.
- The work includes runner config, setup files, fake timers, spies, or snapshots.

## Do not use this skill when

- The test suite already uses Jest — the task is not a migration.
- The ask is to add new tests to an existing Mocha suite without converting it.

## Inputs to gather

**Required before editing**
- The existing Mocha, Chai, and Sinon versions and test bootstrap configuration.
- The repository's current or planned Jest configuration and conventions.

**Helpful if present**
- Any test utilities, global setup, environment assumptions, or module mocking patterns.
- The subset of tests to migrate first and the commands used to run them.

**Only investigate if encountered**
- Non-standard Chai plugins (e.g., `chai-as-promised`, `chai-http`) that need separate handling.

## First move

Inventory what needs to migrate before touching any test files:

```sh
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`](references/assertion-mapping.md) and [`references/mock-mapping.md`](references/mock-mapping.md) before rewriting patterns.

## Workflow

1. Identify all Mocha, Chai, and Sinon patterns in use.
2. Convert a small representative file first and verify the project's Jest setup.
3. Replace assertion styles with idiomatic Jest expectations using the assertion mapping reference.
4. Replace mocks, spies, and stubs with Jest equivalents using the mock mapping reference.
5. Convert shared setup and teardown patterns carefully (`before`/`after` → `beforeAll`/`afterAll`, `beforeEach`/`afterEach` stay the same).
6. Update test utilities, config, or setup files only where required for parity.
7. Migrate incrementally and run the relevant tests after each batch.

## Worked migration slice

Use this as the shape for one end-to-end file before scaling out:

```js
// 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 });
  });
});
```

```js
// 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 });
  });
});
```

## Outputs

- Test files and config updated to Jest (imports, lifecycle, matchers, runners).
- Evidence that the suite runs under Jest with equivalent or improved coverage.

## Guardrails

- **Must** preserve async behavior, timer behavior, and module mocking semantics explicitly.
- **Must** use `await jest.advanceTimersByTimeAsync(n)` — not `jest.advanceTimersByTime(n)` — when the original test used `clock.tickAsync()` inside an async body. Using the synchronous variant silently breaks async ordering.
- **Must not** do bulk mechanical rewrites without validation — migrate in small batches.
- **Should** keep test names and intent stable unless the user asks for broader cleanup.
- **Should** watch for memory or environment differences in CI after migration.

From matt-riley/agent-skills, GPL-3.0.

More from matt-riley/agent-skills

Signals

Stars
4
Forks
0
Open issues
1
Last commit (this folder)
Jun 28, 2026 (4 months ago)
Last release
Oct 23, 2026 (8 days ago)

From GitHub (fetched Oct 24, 2026).

Details

Version
1.0.0
License
GPL-3.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from matt-riley

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get mocha-to-jest-migration running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying mocha-to-jest-migration?

CallGet help
Cite this page

mocha-to-jest-migration skill. Agent Mart. https://agentmart.dev/skills/matt-riley-mocha-to-jest-migration (last updated 2026-10-24)