Skip to content

Commit f65623f

Browse files
authored
docs: fix hook testing example (#1698)
1 parent 4aed54e commit f65623f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/src/pages/guides/testing.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ Once installed, a simple test can be written. Given the following custom hook:
2121

2222
```
2323
export function useCustomHook() {
24-
const { data } = useQuery('customHook', () => 'Hello');
25-
return data;
24+
return useQuery('customHook', () => 'Hello');
2625
}
2726
```
2827

@@ -36,9 +35,11 @@ const wrapper = ({ children }) => (
3635
</QueryClientProvider>
3736
);
3837
39-
const { result } = renderHook(() => useCustomHook(), { wrapper });
38+
const { result, waitFor } = renderHook(() => useCustomHook(), { wrapper });
4039
41-
expect(result.current).toEqual('Hello');
40+
await waitFor(() => result.current.isSuccess);
41+
42+
expect(result.current.data).toEqual("Hello");
4243
```
4344

4445
Note that we provide a custom wrapper that builds the `QueryClient` and `QueryClientProvider`. This helps to ensure that our test is completely isolated from any other tests.

0 commit comments

Comments
 (0)