Skip to content

Commit fd7ef1b

Browse files
committed
internal: Update to use controller returned from renderDataClient
1 parent d01aee4 commit fd7ef1b

File tree

3 files changed

+98
-76
lines changed

3 files changed

+98
-76
lines changed

docs/core/api/Controller.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ and retrieval performance.
2020

2121
- [Managers](./Manager.md) as the first argument in [Manager.getMiddleware()](./Manager.md#getmiddleware)
2222
- React with [useController()](./useController.md)
23-
- [Unit testing hooks](../guides/unit-testing-hooks.md) with [renderDataClient()](./makeRenderDataClient.md#renderdataclient)
23+
- [Unit testing hooks](../guides/unit-testing-hooks.md) with [renderDataClient()](./makeRenderDataClient.md#controller)
2424

2525
```ts
2626
class Controller {

docs/core/api/makeRenderDataClient.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Returned from makeRenderDataClient():
3636

3737
```typescript
3838
type RenderDataClientFunction = {
39-
<P, R, T=any>(
39+
<P, R, T = any>(
4040
callback: (props: P) => R,
4141
options?: {
4242
initialProps?: P;
@@ -103,6 +103,38 @@ Pass a React Component as the wrapper option to have it rendered around the inne
103103

104104
[Controller](./Controller.md) to dispatch imperative effects
105105

106+
```ts
107+
it('should update', async () => {
108+
const id = 5;
109+
const payload = { title: 'first item', id, completed: false };
110+
// highlight-next-line
111+
const { result, controller } = renderDataClient(
112+
() => {
113+
return useSuspense(TodoResource.get, { id });
114+
},
115+
{
116+
initialFixtures: [
117+
{
118+
endpoint: TodoResource.get,
119+
args: [{ id }],
120+
response: [payload],
121+
},
122+
],
123+
},
124+
);
125+
expect(result.current).toEqual(TodoResource.fromJS(payload));
126+
// highlight-start
127+
await act(() => {
128+
await controller.fetch(TodoResource.update, {
129+
id,
130+
title: 'updated title',
131+
});
132+
});
133+
// highlight-end
134+
expect(result.current.title).toBe('updated title');
135+
});
136+
```
137+
106138
### cleanup()
107139

108140
Cleans up all managers used in tests. Should be run in `afterEach()` to ensure each test starts fresh.

0 commit comments

Comments
 (0)