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 mocaronNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
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.
Ensure all expected routes are mocked before testing. Use console logs or custom error handling to detect unmatched routes.
Pass { overwrite: true } to the last mock to replace previous matching mocks, or use method-specific mocks to avoid ambiguity.Follow the current documentation. If upgrading from pre-1.0, rewrite your usage to match the new API.
Use method-specific methods (.get(), .post(), etc.) or explicitly include method in mock matcher.
Use import statement: import { MockServer } from 'mocaron'Choose a different port or ensure mockServer.stop() is called before reusing the same port.
Register the mock before making requests. If multiple mocks match the same path, add { overwrite: true } to the last mock.No dependency data recorded yet.