Skip to content

Commit

Permalink
docs(testing): fix infinite query example (#4328)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnassavickas authored Oct 22, 2022
1 parent 65e965a commit d026e41
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions docs/guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const expectation = nock('http://example.com')

(Notice the `.persist()`, because we'll be calling from this endpoint multiple times)

Now we can safely run our tests, the trick here is to await both `isFetching` and then `!isFetching` after calling `fetchNextPage()`:
Now we can safely run our tests, the trick here is to await for the data assertion to pass:

```ts
const { result, waitFor } = renderHook(() => useInfiniteQueryCustomHook(), { wrapper });
Expand All @@ -186,13 +186,12 @@ expect(result.current.data.pages).toStrictEqual(generateMockedResponse(1));

result.current.fetchNextPage();

await waitFor(() => result.current.isFetching);
await waitFor(() => !result.current.isFetching);

expect(result.current.data.pages).toStrictEqual([
...generateMockedResponse(1),
...generateMockedResponse(2),
]);
await waitFor(() =>
expect(result.current.data.pages).toStrictEqual([
...generateMockedResponse(1),
...generateMockedResponse(2),
]),
);

expectation.done();
```
Expand Down

0 comments on commit d026e41

Please sign in to comment.