Add test to useRequest hook to verify ability to cancel poll. (#113947)

This commit is contained in:
CJ Cenizal 2021-10-05 10:43:44 -07:00 committed by GitHub
parent 244ebca919
commit 35200bea1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -308,6 +308,24 @@ describe('useRequest hook', () => {
expect(getSendRequestSpy().callCount).toBe(2);
});
it(`changing pollIntervalMs to undefined cancels the poll`, async () => {
const { setupErrorRequest, setErrorResponse, completeRequest, getSendRequestSpy } = helpers;
// Send initial request.
setupErrorRequest({ pollIntervalMs: REQUEST_TIME });
// Setting the poll to undefined will cancel subsequent requests.
setErrorResponse({ pollIntervalMs: undefined });
// Complete initial request.
await completeRequest();
// If there were another scheduled poll request, this would complete it.
await completeRequest();
// But because we canceled the poll, we only see 1 request instead of 2.
expect(getSendRequestSpy().callCount).toBe(1);
});
it('when the path changes after a request is scheduled, the scheduled request is sent with that path', async () => {
const {
setupSuccessRequest,