Javascript 无法使用Jasmine和Karma测试Angular http服务
我正在尝试使用Jasmine和Karma测试http拦截器。我得到以下错误:Javascript 无法使用Jasmine和Karma测试Angular http服务,javascript,angular,jasmine,angular-cli,karma-jasmine,Javascript,Angular,Jasmine,Angular Cli,Karma Jasmine,我正在尝试使用Jasmine和Karma测试http拦截器。我得到以下错误: × should return same response to a request HeadlessChrome 80.0.3987 (Windows 10.0.0) Error: In this configuration Angular requires Zone.js at new NgZone (http://localhost:9877/_karma_webpack_/node_modules
× should return same response to a request
HeadlessChrome 80.0.3987 (Windows 10.0.0)
Error: In this configuration Angular requires Zone.js
at new NgZone (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:40482:1)
at R3TestBedCompiler.compileTestModule (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:2357:1)
at R3TestBedCompiler.finalize (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:1874:1)
at TestBedRender3.get testModuleRef [as testModuleRef] (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:3245:1)
at TestBedRender3.inject (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:3102:1)
at Function.inject (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:2987:1)
at UserContext.<anonymous> (http://localhost:9877/_karma_webpack_/src/main/resources/public/scripts/sas/fcs/interceptors/test-interceptor.ng.spec.ts:25:30)
at <Jasmine>
你的设置看起来不寻常。你能分享更多的信息吗?或者说你能做得更好吗?特别是,
MyManagerHTTPInterceptor
,errorResponseInterceptorService
是什么?为什么要手动实例化它们?您好@Shlang,我将添加一个简单的代码作为示例。我无法将代码粘贴到这里。你解决过这个问题吗?我在尝试设置第一次角度服务测试时收到相同的错误消息。我从未使用过CLI,我能找到的大多数示例都假设您使用的是ng test
,因此我不得不或多或少地从头开始设置Karma。我可以测试没有依赖关系的简单函数,但是一旦我尝试使用测试床
,我就遇到了同样的错误。你的设置看起来很不寻常。你能分享更多的信息吗?或者说你能做得更好吗?特别是,MyManagerHTTPInterceptor
,errorResponseInterceptorService
是什么?为什么要手动实例化它们?您好@Shlang,我将添加一个简单的代码作为示例。我无法将代码粘贴到这里。你解决过这个问题吗?我在尝试设置第一次角度服务测试时收到相同的错误消息。我从未使用过CLI,我能找到的大多数示例都假设您使用的是ng test
,因此我不得不或多或少地从头开始设置Karma。我可以测试没有依赖关系的简单函数,但是一旦我尝试使用TestBed
,我就遇到了同样的错误。