question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add supprot for AbortSignal

See original GitHub issue

Fetch request can be cancelled through AbortController API & cross-fetch library used here is wrapper around node-fetch library which does support it

It would be really helpful if AbortController was exposed by this library to allow testing cases where requests may be cancelled.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
akmjenkinscommented, Apr 18, 2019

Those are coming from cross-fetch, not jest-fetch-mock. More importantly, those are part of the specification that need to be supplied by fetch. An AbortController is more generic and, while fetch can make use of an AbortController (by listening to it’s signal), it’s not required for fetch to function (unlike Headers, Response, and Request).

I still fail to see the use case - if you want to test an aborted fetch, then you should already have an implementation of AbortController. Right now jest-fetch-mock still doesn’t support testing aborted fetches, but this is just me advocating for my PR 😄

1reaction
Gozalacommented, Apr 18, 2019

@Gozala I’m probably missing something, but shouldn’t your AbortController instance come from the code your testing, not the testing library?

@akmjenkins if fetch, Headers, Response, Request all come from here I would expect AbortController to do the same

https://github.com/jefflau/jest-fetch-mock/blob/454fcc956de67175567ced958c28b0c33bbd0f10/src/index.js#L49-L52

Read more comments on GitHub >

github_iconTop Results From Across the Web

AbortSignal - Web APIs - MDN Web Docs - Mozilla
The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort ......
Read more >
Add support for AbortSignal · Issue #53 · sindresorhus/p-retry
Sometimes you just want to cancel a retry operation: const abortController = new AbortController(); const {signal} = abortController; ...
Read more >
Using AbortSignal in Node.js - NearForm
Consult the Node.js documentation for more details on exactly which APIs support AbortSignal . More are being added all the time and support...
Read more >
Add support for AbortSignal to cancel requests by jnields · Pull ...
Add support for AbortSignal to cancel requests #539. Merged. bitinn merged 1 commit into node-fetch:master from jnields:add-signal-support on Nov 12, 2018.
Read more >
AbortController & AbortSignal | Can I use... Support ... - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found