错误:无法读取属性获取.将Jest-expo与React Native结合使用 [英] Error : Cannot read property fetch. Using jest-expo with react native

查看:70
本文介绍了错误:无法读取属性获取.将Jest-expo与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作为测试工具,正在其他一些环境中运行它,可能是在严格的环境中运行. thisundefined的模式.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆