Skip to content

Commit b0c2f67

Browse files
docs: Update testing docs to match React Query V3 (#1610)
Updated ReactQueryCacheProvider with QueryClientProvider as current testing documentation does not work when using React Query V3
1 parent 5c93a2e commit b0c2f67

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/src/pages/guides/testing.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ export function useCustomHook() {
2929
We can write a test for this as follows:
3030

3131
```
32-
const queryCache = new QueryCache();
32+
const queryClient = new QueryClient();
3333
const wrapper = ({ children }) => (
34-
<ReactQueryCacheProvider queryCache={queryCache}>
34+
<QueryClientProvider client={queryClient}>
3535
{children}
36-
</ReactQueryCacheProvider>
36+
</QueryClientProvider>
3737
);
3838
3939
const { result } = renderHook(() => useCustomHook(), { wrapper });
4040
4141
expect(result.current).toEqual('Hello');
4242
```
4343

44-
Note that we provide a custom wrapper that builds the `QueryCache` and `ReactQueryCacheProvider`. This helps to ensure that our test is completely isolated from any other tests.
44+
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.
4545

46-
It is possible to write this wrapper only once, but if so we need to ensure that the `QueryCache` gets cleared before every test, and that tests don't run in parallel otherwise one test will influence the results of others.
46+
It is possible to write this wrapper only once, but if so we need to ensure that the `QueryClient` gets cleared before every test, and that tests don't run in parallel otherwise one test will influence the results of others.
4747

4848
## Testing Network Calls
4949

@@ -62,11 +62,11 @@ function useFetchData() {
6262
We can write a test for this as follows:
6363

6464
```
65-
const queryCache = new QueryCache();
65+
const queryClient = new QueryClient();
6666
const wrapper = ({ children }) => (
67-
<ReactQueryCacheProvider queryCache={queryCache}>
67+
<QueryClientProvider client={queryClient}>
6868
{children}
69-
</ReactQueryCacheProvider>
69+
</QueryClientProvider>
7070
);
7171
7272
const expectation = nock('http://example.com')

0 commit comments

Comments
 (0)