Skip to content

toolstackhq/mockit

Repository files navigation

MockIt

Build Tests Docs Coverage License npm npm downloads Release Last Commit

MockIt is a REST API mocking library for JavaScript and TypeScript.

It supports three runtime patterns:

  • MockServer: run a real mock API on a local port
  • HttpInterceptor: intercept outbound HTTP in the current Node process
  • RemoteMockServer: change a running MockServer from tests or scripts
Feature Use case
MockServer Run a real mock API server for frontend development, browser automation, or any other process that needs a URL to call.
HttpInterceptor Intercept fetch, http, https, and Axios inside the current Node process without starting a server.
RemoteMockServer Update a running standalone mock from Playwright, API tests, or external scripts.
TypeScript defaults Load reusable default mocks from a typed config file.
OpenAPI / Swagger loading Generate mock endpoints and sample responses from an API spec.
Request matching Match by method, headers, cookies, query, bearer token, and body.
Response control Return delays, templates, faults, sequences, and limited-use responses.
Dashboard and admin APIs Inspect mocks, requests, unmatched calls, and pending expectations.

Live docs: https://toolstackhq.github.io/mockit/

Install:

npm install @toolstackhq/mockit

Choose A Runtime

Use MockServer when:

  • a browser, UI, or another process must call a real HTTP endpoint
  • you want a mock to stay running outside a test process
  • manual testers or QA automation need a stable fake backend

Use HttpInterceptor when:

  • the code under test already runs in Node
  • you want to fake outbound HTTP without starting a server
  • your Node code uses fetch, Axios, http, or https

Use RemoteMockServer when:

  • MockServer is already running
  • the test should change mock behavior without starting the server itself

Quick Start

Create a TypeScript config:

npx @toolstackhq/mockit init

In a terminal, init can either:

  • write the default starter config
  • ask a few questions and generate endpoints for you

Start a standalone mock:

npx @toolstackhq/mockit serve --config ./mockit.config.ts --port 3001

The dashboard is available at:

http://127.0.0.1:3001/_mockit

TypeScript Config Example

import { defineConfig } from '@toolstackhq/mockit';

export default defineConfig([
  {
    path: '/api/balance',
    method: 'GET',
    response: {
      status: 200,
      body: { balance: 200, currency: 'AUD' },
    },
  },
]);

In-Process Interceptor Example

Use HttpInterceptor when your code already runs in Node and you do not want to start a mock server.

import axios from 'axios';
import { HttpInterceptor } from '@toolstackhq/mockit';

const interceptor = new HttpInterceptor({ onUnhandled: 'fail' });

interceptor.expect('/api/users')
  .method('GET')
  .returns(200)
  .withBody([{ id: 1, name: 'Jane Doe' }]);

interceptor.enable();

const response = await axios.get('https://api.example.com/api/users');
console.log(response.data);

interceptor.disable();

The request still looks like a real outbound HTTP call, but MockIt returns the response inside the same Node process.

npm Script

{
  "scripts": {
    "mockit": "mockit serve --config ./mockit.config.ts --port 3001"
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors