Open niksajanjic opened 7 years ago
I have to point out that I copied your source code directly into my setupTest.js function and it works perfectly so it definitely isn't the code that is the problem. Something else is the cause of the problem which I still haven't figured out, maybe it's the way babel is resolving imports, but this is just a wild guess from my side. There's a good chance it has nothing to do with this module, but for now I'm leaving it open as it does break on it's import.
Anyways, I would suggest to update README and mention that this module works in default jsdom environment, but doesn't for instance in node as it expects window object to be defined with adjoining Response, Header, Request, Promise API.
Same for me, copying in my project works
I have the same question
Just to let you know guys, I wasn't able to figure out what was the issue and I didn't have time to dig deep and fix it, so I switched to another module called fetch-mock which I also use inside my Jest framework and it work in jsdom and node environment.
Hey guys! I am having same issues in Node versions < 7. As @niksajanjic for now, fetch-mock
fixed issue, but it will be awesome if we can fix this module too!
+1 for fixing this. I think this is the simplest mock for fetch I have seen.
For me it was a node version issue. I was using 4, when I set my node version to 6.9.5 or 7 it worked.
If you use nvm: nvm use 6
or nvm use 7
You may need to install those versions if you don't have them.
This seems to be because this package uses array destructuring, which wasn't supported until node v6.
I suggest that the engines key in the package.json
specify node v6, to alert users to the minimum compatible version. @jefflau, would you accept such a PR? Or, would you rather change the code to work in older versions of node?
Same issue for me. My node version in production is 4.8.4 (because of Meteor), installing node packages with a later version of node leads to incompatibility issues, so I cannot upgrade my node version.
Is there any other solution than upgrading node version?
Sorry for the late responses. I originally wrote the package with only the browser in mind and since most people use babel, I didn't think it would be an issue.
@IanVS I would accept a PR to do that. I have been off the ball a bit lately. Also I am unfamiliar with how the engines key works so I'll have to do some reading, but I think it sounds like a solid fix. I'm too used to ES6+ syntax so I wouldn't want to go backwards :)
@aymericbouzy If you still need this package, I think the best method would be to use babel with Jest to make sure jest runs through babel first. I think that should work, but let me know if it doesn't
● Test suite failed to run
package.json
setupTest.js
EDIT: Removing testEnvironment and using jsdom doesn't help. I see I can't use your module as I'm running my tests in node environment because it's much faster than jsdom so I'm going to mock it by myself.