Registry / testing / mocaron

mocaron

JSON →
library1.1.0jsnpmunverified

Simple express mock server with a flexible API inspired by fetch-mock. Version 1.1.0 provides a lightweight, TypeScript-friendly solution for mocking HTTP endpoints during testing. It offers method-specific mocks (get, post, put, patch, delete), supports overwriting ambiguous mocks, and automatic 404 for unmatched or ambiguous requests. Released under MIT, with no critical dependencies. Differentiators include an intuitive chainable API and zero external runtime deps beyond express.

npm install mocaron
INSTALL
IMPORT
SIG · MOCARON
M
mocaron
testingjavascriptv1.1.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.

MockServer
import { MockServer } from 'mocaron'
const MockServer = require('mocaron')
TypeScript-friendly with bundled types. ESM-only package; use import syntax.

Creates a mock server on port 3000, registers a GET mock for /test, sends a fetch request, logs the status and body, then stops the server.

import { MockServer } from 'mocaron'; const mockServer = new MockServer({ port: 3000 }); await mockServer.start(); mockServer.get('/test', { status: 200, body: { message: 'Hello World' } }); const response = await fetch('http://localhost:3000/test'); console.log(response.status); // 200 console.log(await response.json()); // { message: 'Hello World' } await mockServer.stop();
Debug
Known issues
gotchaUnmatched requests return 404 silently — no warning or error thrown.
fix
Ensure all expected routes are mocked before testing. Use console logs or custom error handling to detect unmatched routes.
affects: >=1.0.0
gotchaAmbiguous mocks (two mocks matching the same request) also return 404 by default, not an error.
fix
Pass { overwrite: true } to the last mock to replace previous matching mocks, or use method-specific mocks to avoid ambiguity.
affects: >=1.0.0
breakingVersion 1.0.0 introduced the MockServer as the primary API; previous alpha/beta versions used different APIs and are not compatible.
fix
Follow the current documentation. If upgrading from pre-1.0, rewrite your usage to match the new API.
affects: >=1.0.0
deprecatedNo deprecation warnings currently; the API is stable.
affects: none
gotchaDefault method for mock() is GET? Actually it's inferred from path matching. Always specify method explicitly for clarity.
fix
Use method-specific methods (.get(), .post(), etc.) or explicitly include method in mock matcher.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mocaron_1.MockServer is not a constructor
Using CommonJS require() instead of ESM import.
fix
Use import statement: import { MockServer } from 'mocaron'
Error: listen EADDRINUSE :::3000
Port already in use by another process or previous mock server not stopped.
fix
Choose a different port or ensure mockServer.stop() is called before reusing the same port.
404 response for a mocked route
Route not registered before the request, or ambiguous mocks defined without overwrite:true.
fix
Register the mock before making requests. If multiple mocks match the same path, add { overwrite: true } to the last mock.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
mocaron — npm install mocaron · libregistry