【发布时间】:2019-01-29 17:20:36
【问题描述】:
我是 karma 和 jasmine 的新手,如果这听起来很愚蠢,请原谅我。我有以下这些代码,我想用它做什么,就是找出我接下来需要做什么。我在hello-http.service.ts 的构造函数中注入了CUSTOM_HTTP_CONFIG,我找不到如何实现这一点的教程,手动注入依赖项,这就是我认为错误消息抱怨的原因。
test.spec.ts
beforeEach(async(() => {
TestBed.configureTestingModule({
declaration: [...],
imports[RouterTestingModule, ...],
providers: [HelloHttpService, ...],
});
});
hello-http.service.ts
constructor(
@Inject(CUSTOM_HTTP_CONFIG) protect config: CustomHttpParams,
...
) {
super(config, http);
}
因果报应:错误
Failed: Uncaught (in promise): Error: StaticInjectorError(DynamicTestModule)[HelloHttpService -> InjectionToken Custom HTTP Config]:
StaticInjectorError(Platform: core)[HelloHttpService -> InjectionToken Custom HTTP Config]:
NullInjectorError: No provider for InjectionToken Custom HTTP Config!
Error: StaticInjectorError(DynamicTestModule)[HelloHttpService -> InjectionToken Custom HTTP Config]:
StaticInjectorError(Platform: core)[HelloHttpService -> InjectionToken Custom HTTP Config]:
NullInjectorError: No provider for InjectionToken Custom HTTP Config!
at _NullInjector.webpackJsonp../node_modules/@angular/core/esm5/core.js._NullInjector.get (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/esm5/core.js:1003:1)
at resolveToken (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/esm5/core.js:1301:1)
【问题讨论】:
标签: angular typescript unit-testing karma-jasmine