Skip to content

Commit

Permalink
add a failing test for StrictMode polling
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Jun 22, 2021
1 parent bfa2128 commit 88c134e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,69 @@ describe('useQuery Hook', () => {
}
);

itAsync(
'stop polling and start polling should work with StrictMode',
(resolve, reject) => {
const query = gql`
query car {
car {
id
make
}
}
`;

const data1 = {
car: {
id: 1,
make: 'Venturi',
__typename: 'Car',
}
};

const mocks = [
{ request: { query }, result: { data: data1 } },
];

let renderCount = 0;
const Component = () => {
let { data, loading, stopPolling } = useQuery(query, {
pollInterval: 100,
});

switch (++renderCount) {
case 1:
case 2:
expect(loading).toBeTruthy();
expect(data).toBeUndefined();
break;
case 3:
case 4:
expect(loading).toBeFalsy();
expect(data).toEqual(data1);
stopPolling();
break;
default:
reject(new Error('Unexpected render count'));
}

return null;
};

render(
<React.StrictMode>
<MockedProvider link={new MockLink(mocks).setOnError(reject)}>
<Component />
</MockedProvider>
</React.StrictMode>
);

return wait(() => {
expect(renderCount).toBe(4);
}).then(() => setTimeout(resolve, 300), reject);
},
);

it('should set called to true by default', () => {
const Component = () => {
const { loading, called } = useQuery(CAR_QUERY);
Expand Down

0 comments on commit 88c134e

Please sign in to comment.