Skip to content

Commit a4ecb29

Browse files
authored
docs: mocking (#270)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a new sidebar entry under "Advanced" for quick access to additional guidance. - **Documentation** - Introduced a new "Mocking" guide detailing approaches for creating alternative implementations for testing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b7b8dc2 commit a4ecb29

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

apps/content/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export default defineConfig({
147147
{ text: 'Validation Errors', link: '/docs/advanced/validation-errors' },
148148
{ text: 'RPC Protocol', link: '/docs/advanced/rpc-protocol' },
149149
{ text: 'RPC JSON Serializer', link: '/docs/advanced/rpc-json-serializer' },
150+
{ text: 'Mocking', link: '/docs/advanced/mocking' },
150151
{ text: 'Exceeds the maximum length ...', link: '/docs/advanced/exceeds-the-maximum-length-problem' },
151152
],
152153
},
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Mocking
3+
description: Easily mock your oRPC handlers for testing.
4+
---
5+
6+
# Mocking
7+
8+
Mock your oRPC handlers with ease.
9+
10+
::: warning
11+
This page is incomplete and may be missing important information.
12+
:::
13+
14+
## Using the Implementer
15+
16+
The [Implementer](/docs/contract-first/implement-contract#the-implementer) is designed for contract-first development. However, it can also be used to create alternative versions of your [router](/docs/router) or [procedure](/docs/procedure) for testing purposes.
17+
18+
```ts twoslash
19+
import { router } from './shared/planet'
20+
// ---cut---
21+
import { implement, unlazyRouter } from '@orpc/server'
22+
23+
const fakeListPlanet = implement(router.planet.list).handler(() => [])
24+
```
25+
26+
You can now use `fakeListPlanet` to replace `listPlanet`. Additionally, the `implement` function can be used to create a fake server for front-end testing.
27+
28+
::: warning
29+
The `implement` function does not support the [lazy router](/docs/router#lazy-router) yet. Please use the `unlazyRouter` utility to convert your lazy router before implementing.
30+
:::

0 commit comments

Comments
 (0)