jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
886 stars 117 forks source link

DOMException is not defined #159

Closed thecodecafe closed 3 years ago

thecodecafe commented 4 years ago

Hi, I'm trying to test for an aborted request but keep getting this reference error, DOMException is not defined, I've included the AbortController and AbortSignal polypill for fetch in my test environment and everything works fine until it gets here, is there a way to get an actual AbortError exception using jest-fetch-mock when a request is aborted? Thanks!

yinzara commented 4 years ago

What is your jest "testEnvironment" set to? It's probably supposed to be "jsdom" if you're testing an app that runs in a browser.

thecodecafe commented 4 years ago

Hi @yinzara it was set to node as I was working on a react-native project but changing to jsdom made it work, I'm hoping this does not cause problems in the future but right now, that solved the problem. Thanks a bunch!

yinzara commented 4 years ago

Actually, taking a look at this again, I'm going to reopen this. We should be using some kind of Polyfill of DOMException as it is not present in Node. Asking you to change your test environment to jsdom is not appropriate.