Skip to content

Installation

Install the mock as a dev dependency — it is a testing tool and should not ship in your production bundle.

Terminal window
pnpm add -D @labdigital/commercetools-mock

The package declares two peer dependencies that you install alongside it:

PackageVersionWhy
msw^2.14.6Intercepts the HTTP requests your code makes.
@commercetools/platform-sdk>= 8.25.0Provides the resource type definitions the mock is typed against.
Terminal window
pnpm add -D msw @commercetools/platform-sdk
  • Node.js ≥ 22. The library is published as ESM ("type": "module") and uses modern Node APIs (the optional SQLite backend relies on the built-in node:sqlite module).
  • A test runner such as Vitest or Jest — the examples in these docs use Vitest.

The package exposes two entry points:

// Main entry — the mock, storage and helpers
import { CommercetoolsMock } from '@labdigital/commercetools-mock'
// Optional SQLite storage backend
import { SQLiteStorage } from '@labdigital/commercetools-mock/sqlite'

Next: build a working test in the Quick start.