{"id":25542,"library":"esmocha","title":"esmocha","description":"Mocha wrapper with built-in TypeScript support via esbuild, integrated Jest-compatible expect, mock, and snapshot testing. Current stable version is v5.0.0, released in 2025. Release cadence is irregular with major versions marking breaking changes. Key differentiators include zero-config TypeScript execution, Jest-compatible API for familiar testing patterns, and automatic ESM support for Node >=18.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/mshima/esmocha","tags":["javascript","mocha","typescript","esbuild","mock","expect","snapshot","jest-snapshot","jest-mock"],"install":[{"cmd":"npm install esmocha","lang":"bash","label":"npm"},{"cmd":"yarn add esmocha","lang":"bash","label":"yarn"},{"cmd":"pnpm add esmocha","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"provides TypeScript transformation","package":"@node-loaders/esbuild","optional":false},{"reason":"test runner wrapper","package":"mocha","optional":false}],"imports":[{"note":"ESM-only since v1; no CommonJS support.","symbol":"expect","correct":"import { expect } from 'esmocha'"},{"symbol":"mock","correct":"import { mock } from 'esmocha'"},{"symbol":"resetAllMocks","correct":"import { resetAllMocks } from 'esmocha'"},{"note":"Re-exported from mocha; prefer importing from esmocha for consistency.","wrong":"import { afterAll } from 'mocha'","symbol":"afterAll","correct":"import { afterAll } from 'esmocha'"}],"quickstart":{"code":"npm install esmocha --save-dev\necho \"export function add(a: number, b: number) { return a + b; }\" > add.ts\necho \"import { expect } from 'esmocha';\nimport { add } from './add.js';\ndescribe('add', () => {\n  it('should add two numbers', () => {\n    expect(add(1, 2)).toBe(3);\n  });\n});\" > test.spec.ts\nnpx esmocha","lang":"typescript","description":"Installs esmocha, creates a simple TypeScript module and test, then runs the test using esmocha."},"warnings":[{"fix":"Use --loader @node-loaders/esbuild or configure in mocha options.","message":"v5.0.0 makes loader optional; if you relied on automatic esbuild loader, you may need to register it manually.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Update snapshots with npx esmocha --update-snapshot.","message":"v4.0.0 updated mocha-expect-snapshot and jest-mock, potentially breaking snapshot file formats.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use import syntax and ensure package.json has type: module.","message":"esmocha is ESM-only; require() will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node to supported version.","message":"Node.js version must be ^18.19.0 || ^20.9.0 || ^22.0.0 || >=24.0.0; older versions may not work.","severity":"gotcha","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change to import { expect } from 'esmocha' and enable ESM in your project.","cause":"Attempted to use require with ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module esmocha not supported."},{"fix":"Use import { expect } from 'esmocha' rather than import expect from 'esmocha'.","cause":"Misconfigured import: using default import instead of named import.","error":"TypeError: Expect is not a function"},{"fix":"Run npm install @node-loaders/esbuild --save-dev.","cause":"Missing peer dependency @node-loaders/esbuild.","error":"Error: Cannot find module '@node-loaders/esbuild'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}