New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GlobalFetch API - Headers, Request, Response #1724
Comments
+1 would be nice as General availability in browsers means more web apps use it and fail in JSDOM. |
No, unfortunately the whatwg-fetch polyfill is not very spec compliant. Someone needs to write an implementation of the fetch algorithm in the standard: https://fetch.spec.whatwg.org/#fetching That said, in your own usage of jsdom you're welcome to include |
Yes, for now I'm using the whatwg polyfill in JSDOM. It would be nice to see something built-in, though. Especially since the |
Yeah, it definitely would be nice! I hope someone is able to pull-request an implementation of the spec. |
My application tests run in node rather than the browser. The lack of server-side fetch API (and typescript bindings to match) has become a show-stopper. This issue looks like the most promising solution. Does anyone else know of a workaround for the mean-time? I can use fetch in the browser. I can use node-fetch for tests, but I can't switch on the two packages dynamically. One environment or the other will always fail. Edit: whatwg-fetch seems to be the answer. Install the package, dont install the typings. import it only in the test runner so the browser application does not have conflicting definitions |
Is this issue still relevant since v15 supports |
v15 does not support fetch. |
Sorry, i misread the Changelog about the 15.1, only Headers was provided |
This comment has been minimized.
This comment has been minimized.
My workaround looks like this:
|
but in all seriousness, I have an easy workaround: First, .. then .. jest.config.js:
setupJest.js:
and then you'll automagically have all of the |
Jest does not include Node's fetch: jsdom/jsdom#1724 Previously we had cross-fetch included by a library but that was removed in f594a70 so a workaround is needed.
Jest does not include Node's fetch: jsdom/jsdom#1724 Previously we had cross-fetch included by a library but that was removed in f594a70 so a workaround is needed.
Jest does not include Node's fetch: jsdom/jsdom#1724 Previously we had cross-fetch included by a library but that was removed in f594a70 so a workaround is needed.
I've fixed this by using the |
- It is needed by JSDOM, which doesn't support fetch (jsdom/jsdom#1724). - TODO: only include the fetch polyfill for the replication test.
- It is needed by JSDOM, which doesn't support fetch jsdom/jsdom#1724 - TODO: only include the fetch polyfill for the replication test
I just want to add on to the suggested workaround of patching
|
- jest-environment-jsdom: Not included by default in Jest. It emulates a web browser environment to test our code. - whatwg-fetch: (more info in here: jsdom/jsdom#1724) It seems JSDom environment does not have support for globalThis.fetch method. Since this is what we want to test, I found in this issue a workaround so we can invoke the method in our tests.
- jest-environment-jsdom: Not included by default in Jest. It emulates a web browser environment to test our code. - whatwg-fetch: (more info in here: jsdom/jsdom#1724) It seems JSDom environment does not have support for globalThis.fetch method. Since this is what we want to test, I found in this issue a workaround so we can invoke the method in our tests.
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
https://developer.mozilla.org/en-US/docs/Web/API/Headers
https://developer.mozilla.org/en-US/docs/Web/API/Request
https://developer.mozilla.org/en-US/docs/Web/API/Response
The text was updated successfully, but these errors were encountered: