oRPC Testing & Mocking
Test oRPC procedures using server-side clients, and mock implementations for frontend testing.
SKILL.mdskills/orpc-testing-mocking/SKILL.md
GitHubTesting & Mocking
Strategies for testing and mocking oRPC routers and procedures.
Testing
Use Server-Side Clients to invoke procedures directly in tests, no additional setup required:
import { call } from '@orpc/server'
it('works', async () => {
await expect(
call(router.planet.list, { page: 1, size: 10 })
).resolves.toEqual([
{ id: '1', name: 'Earth' },
{ id: '2', name: 'Mars' },
])
})
You can also use the Fetch API to create production-like clients. See Optimize SSR.
Mocking
The Implementer is designed for contract-first development, but it can also create alternative versions of routers/procedures for testing.
import { implement, unlazyRouter } from '@orpc/server'
const fakeListPlanet = implement(router.planet.list).handler(() => [])
Use fakeListPlanet to replace the actual listPlanet implementation during tests.
implementis also useful for creating mock servers for frontend testing scenarios.
implementdoesn't yet support lazy routers — use theunlazyRouterutility to convert before implementing.