Registry / testing / esmocha

esmocha

JSON →
library5.0.0jsnpmunverified

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.

npm install esmocha
INSTALL
IMPORT
SIG · ESMOCHA
E
esmocha
testingjavascriptv5.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

expect
import { expect } from 'esmocha'
ESM-only since v1; no CommonJS support.
mock
import { mock } from 'esmocha'
resetAllMocks
import { resetAllMocks } from 'esmocha'
afterAll
import { afterAll } from 'esmocha'
import { afterAll } from 'mocha'
Re-exported from mocha; prefer importing from esmocha for consistency.

Installs esmocha, creates a simple TypeScript module and test, then runs the test using esmocha.

npm install esmocha --save-dev echo "export function add(a: number, b: number) { return a + b; }" > add.ts echo "import { expect } from 'esmocha'; import { add } from './add.js'; describe('add', () => { it('should add two numbers', () => { expect(add(1, 2)).toBe(3); }); });" > test.spec.ts npx esmocha
esmocha --version
Debug
Known issues
breakingv5.0.0 makes loader optional; if you relied on automatic esbuild loader, you may need to register it manually.
fix
Use --loader @node-loaders/esbuild or configure in mocha options.
affects: >=5.0.0
breakingv4.0.0 updated mocha-expect-snapshot and jest-mock, potentially breaking snapshot file formats.
fix
Update snapshots with npx esmocha --update-snapshot.
affects: >=4.0.0
gotchaesmocha is ESM-only; require() will fail.
fix
Use import syntax and ensure package.json has type: module.
affects: >=1.0.0
gotchaNode.js version must be ^18.19.0 || ^20.9.0 || ^22.0.0 || >=24.0.0; older versions may not work.
fix
Upgrade Node to supported version.
affects: >=5.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module esmocha not supported.
Attempted to use require with ESM-only package.
fix
Change to import { expect } from 'esmocha' and enable ESM in your project.
TypeError: Expect is not a function
Misconfigured import: using default import instead of named import.
fix
Use import { expect } from 'esmocha' rather than import expect from 'esmocha'.
Error: Cannot find module '@node-loaders/esbuild'
Missing peer dependency @node-loaders/esbuild.
fix
Run npm install @node-loaders/esbuild --save-dev.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
@node-loaders/esbuildrequiredprovides TypeScript transformation
mocharequiredtest runner wrapper
Agent activity
4 hits · last 30 days
node
4
Resources
esmocha — npm install esmocha · libregistry