纱线测试失败-网络请求失败 [英] Yarn test failing - Network request failed

查看:129
本文介绍了纱线测试失败-网络请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用create-react-app创建了一个react项目,但是当运行yarn test来查看初始测试是否通过

I created a react project using create-react-app however when ran yarn test to see if the initial tests pass I get

TypeError: Network request failed
    at XMLHttpRequest.xhr.onerror (/home/ubuntu/wonderland/hackernews/node_modules/whatwg-fetch/fetch.js:436:16)
    at XMLHttpRequest.callback.(anonymous function) (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:289:32)
    at invokeEventListeners (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:219:27)
    at invokeInlineListeners (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:166:7)
    at EventTargetImpl._dispatch (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)
    at EventTargetImpl.dispatchEvent (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
    at XMLHttpRequest.dispatchEvent (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:61:35)
    at XMLHttpRequest.abort (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:405:16)
    at Object.abort (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:315:13)
    at RequestManager.close (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:146:21)
    at Window.close (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/browser/Window.js:362:29)
    at JSDOMEnvironment.dispose (/home/ubuntu/wonderland/hackernews/node_modules/jest-environment-jsdom/build/index.js:44:19)
    at Promise.resolve.then (/home/ubuntu/wonderland/hackernews/node_modules/jest-cli/build/runTest.js:102:17)

我正在使用ssh在Cloud9编辑器中工作,该ssh连接到AWS托管的我的开发服务器(Ubuntu).在我的本地计算机(Ubuntu)上,测试工作正常.

I'm working in Cloud9 editor using ssh connected to my dev server (Ubuntu) hosted in AWS. Tests are working fine in my local machine (Ubuntu).

感谢您的帮助!

推荐答案

我已经解决了我的问题.我正在看一本名为《学习React之路》的书,我认为引起我的错误的那部分是我从外部API提取数据的部分.这本书忘了包括要提取的导入内容,即:

I already solve my problem. I'm following a book entitled "The Road to Learn React" and I think that the one causing my error is the part where I fetch data from an external API. The book forgot to include an import for fetch which is this one:

import fetch from 'isomorphic-fetch'

然后,它像魅力一样解决了我的问题.

Then, it solves my problem like a charm.

这篇关于纱线测试失败-网络请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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