gpt4 book ai didi

javascript - 错误 : Cannot read property fetch. 将 jest-expo 与 React Native 一起使用

转载 作者:行者123 更新时间:2023-12-03 13:19:31 26 4
gpt4 key购买 nike

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 运行测试时出现错误。如果有人有解决方案请分享。

最佳答案

显然这是没有代码片段的猜测,但看看 what fetch.js looked like at the time ,我们无法读取其 fetch 属性的 undefined 值是变量 self (参见第 1 行),该值原本应设置为this 上下文(参见第 466 行)。

因此,看起来 fetch.js 期望在 this 引用 window 的环境中运行,但是 jest-expo 是一个测试工具,正在其他环境中运行它,可能是在严格模式下,其中 this未定义

关于javascript - 错误 : Cannot read property fetch. 将 jest-expo 与 React Native 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47111767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com