Chrome 59.0.3071(Mac OS X 10.11.6)错误未获取状态的响应:404未找到URL

问题描述:

我正在使用Jasmine和Karma进行我的前端单元测试。当运行我的测试中,我得到了以下错误:Chrome 59.0.3071(Mac OS X 10.11.6)错误未获取状态的响应:404未找到URL

终端错误

Chrome 59.0.3071 (Mac OS X 10.11.6) ERROR Uncaught Response with status: 404 Not Found for URL: http://localhost:9876/api/volunteer at http://localhost:9876/_karma_webpack_/polyfills.bundle.js:2604 Chrome 59.0.3071 (Mac OS X 10.11.6): Executed 4 of 6 ERROR (0 secs/1.02 secs) Chrome 59.0.3071 (Mac OS X 10.11.6) ERROR Uncaught Response with status: 404 Not Found for URL: http://localhost:9876/api/volunteer Chrome 59.0.3071 (Mac OS X 10.11.6): Executed 4 of 6 ERROR (1.433 secs/1.02 secs)

浏览器错误

SignUpComponent should be created [object ErrorEvent] thrown SignUpComponent form should clear on submit [object ErrorEvent] thrown

我想不通,为什么终端告诉我,我有一个404错误,浏览器告诉我在sign-up.component.spec中有一个错误。 TS。 sign-up.component.spec.ts不会发出任何http请求。

SignUpComponent可以在客户端/应用/签上/登录up.component.spec.ts在以下库中找到: https://github.com/cerberus-org/cerberus-app

东西试图调试的时候是,如果我注释掉的客户,我注意到/app/shared/volunteer.service.spec.ts即使错误指向client/app/sign-up/sign-up.component.spec.ts,所有测试都会通过。

任何洞见赞赏。

我相信我收到了这个错误,因为后端没有被正确地模拟。我没有使用XHRBackend,所以当其他测试尝试进行http调用时,调用不会被模拟后端拦截和处理。

我能按照本教程正确嘲笑我的后端: https://semaphoreci.com/community/tutorials/testing-services-in-angular-2

本教程的“其余”部分是最相关的。