Skip to main content

WireMock Testcontainers for Node.js

Mock HTTP APIs in Node.js integration tests: WireMock in Testcontainers, with a fluent TypeScript API.

npm install --save-dev @hellaweb3/wiremock-testcontainers-nodejs

A fluent, typed builder

Stubs from recorded directories, files, npm packages or inline objects – validated as you register them, long before Docker starts.

Verify real HTTP

Assert on what your code actually sent with countRequests() and findRequests() – WireMock's request matching, fully typed.

Fast isolation

One container per suite; reset() restores stubs, scenarios and the journal between tests in milliseconds – no restarts.

WireMock extensions

Load compiled extension JARs and wrap them in TypeScript extensions with typed stub helpers – no JDK needed.

No Docker? Develop anyway

For local development, serve every container from a local WireMock JVM – refused in CI/CD, so Docker stays the source of truth.

Examples that cannot drift

Every snippet on this site is embedded from an examples project that is type-checked, linted and tested against WireMock.

A complete test suite

import { afterAll, afterEach, beforeAll, expect, it } from "vitest"; // or Jest
import { type StartedWiremockContainer, WiremockContainer } from "@hellaweb3/wiremock-testcontainers-nodejs";
import { PaymentsClient } from "../app/payments-client"; // the code under test

let wiremock: StartedWiremockContainer;

beforeAll(async () => {
  wiremock = await new WiremockContainer()
    .withMappings("./__mocks__/wiremock") // mappings/ + __files/
    .start();
  await wiremock.waitUntilReady();
}, 120_000); // the first image pull can be slow

afterEach(() => wiremock.reset()); // pristine stubs, empty journal – no restart
afterAll(() => wiremock?.stop());

it("lists the recorded payments", async () => {
  const page = await new PaymentsClient(wiremock.getUrl()).list();

  expect(page.meta.totalItems).toBe(2);
  expect(await wiremock.countRequests({ method: "GET", url: "/payments" })).toBe(1);
});

Source: examples/getting-started/quick-start.e2e.test.ts (lines 8–29)