Skip to content

Commit

Permalink
add a failing test for #8697
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Aug 27, 2021
1 parent f7bda84 commit 69b3336
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,40 @@ describe('useQuery Hook', () => {
expect(result.current.loading).toBe(false);
expect(result.current.data).toEqual(mocks[1].result.data);
});

it('should not use the cache when using `network-only`', async () => {
const query = gql`{ hello }`;
const mocks = [
{
request: { query },
result: { data: { hello: 'from link' } },
},
];

const cache = new InMemoryCache();
cache.writeQuery({
query,
data: { hello: 'from cache' },
});

const { result, waitForNextUpdate } = renderHook(
() => useQuery(query, { fetchPolicy: 'network-only' }),
{
wrapper: ({ children }) => (
<MockedProvider mocks={mocks} cache={cache}>
{children}
</MockedProvider>
),
},
);

expect(result.current.loading).toBe(true);
expect(result.current.data).toBe(undefined);

await waitForNextUpdate();
expect(result.current.loading).toBe(false);
expect(result.current.data).toEqual({ hello: 'from link' });
});
});

describe('polling', () => {
Expand Down

0 comments on commit 69b3336

Please sign in to comment.