diff --git a/docs/guides/testing.md b/docs/guides/testing.md index c5838ce4af..9cdff3dda1 100644 --- a/docs/guides/testing.md +++ b/docs/guides/testing.md @@ -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 }); @@ -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(); ```