Skip to content

Testing with Carbon

A common pattern is to start one replica per test file, reset state between tests, and save snapshots at logical checkpoints.

import { beforeAll, afterAll, beforeEach, test } from 'vitest';
import { carbon } from '@carbon/sdk';
let replica: Awaited<ReturnType<typeof carbon.emulate>>;
beforeAll(async () => {
replica = await carbon.emulate({ from: './stripe.json', port: 0 });
});
afterAll(() => replica.close());
beforeEach(() => replica.state.reset());
test('checkout flow', async () => {
// point your app at replica.url and assert as usual
});