website/src/content/docs/actors/testing.mdx
To set up testing with Rivet:
# Install Vitest
npm install -D vitest
# Run tests
npm test
Rivet includes a test helper called setupTest that starts your registry in test mode and returns a client connected to it. This allows for fast, isolated tests without external dependencies.
State persists within each test, allowing you to verify that your actor correctly maintains state between operations.
<CodeSnippet file="examples/docs/actors-testing/testing-state.ts" />For actors that emit events, you can verify events are correctly triggered by subscribing to them:
<CodeSnippet file="examples/docs/actors-testing/testing-events.ts" />Rivet's schedule functionality can be tested by scheduling work and waiting for it to run:
<CodeSnippet file="examples/docs/actors-testing/testing-schedules.ts" />Use a short schedule and expect.poll the action's observable result. Vitest's fake date and fake JavaScript timers do not advance RivetKit's scheduler, which runs outside the test's JavaScript timer queue.
setupTest starts the registry and disposes the returned client when the test finishes, so you can focus on writing effective tests for your business logic.
setupTest - Test setup helper function