Error : Cannot read property fetch. Using jest-expo with react native

二次信任 提交于 2019-12-06 20:22:23

问题


TypeError: Cannot read property 'fetch' of undefined

  at node_modules/whatwg-fetch/fetch.js:4:8
  at Object.<anonymous> (node_modules/whatwg-fetch/fetch.js:466:3)
  at Object.<anonymous> (node_modules/jest-expo/src/setup.js:97:348)

Got error while running tests with jest-expo. If anyone have solution please share.


回答1:


Obviously this is a guess without a code snippet, but looking at what fetch.js looked like at the time, the undefined value whose fetch property we can't read is the variable self (see line 1), which was meant to be set to the this context (see line 466).

Therefore, it seems that fetch.js is expecting to run in an environment where this refers to the window, but jest-expo, being a testing tool, is running it in some other environment, probably in strict mode where this is undefined.



来源:https://stackoverflow.com/questions/47111767/error-cannot-read-property-fetch-using-jest-expo-with-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!