错误:无法读取属性获取.将Jest-expo与React Native结合使用 [英] Error : Cannot read property fetch. Using jest-expo with react native
问题描述
TypeError :无法读取未定义的属性"fetch"
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)
使用jest-expo运行测试时出现错误.如果有人有解决方案,请分享.
Got error while running tests with jest-expo. If anyone have solution please share.
推荐答案
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).
因此,似乎fetch.js
期望在this
引用window
的环境中运行,但是jest-expo
作为测试工具,正在其他一些环境中运行它,可能是在严格的环境中运行. this
是undefined
的模式.
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
.
这篇关于错误:无法读取属性获取.将Jest-expo与React Native结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!