我有注射令牌:
export const IS_SEO_PAGE = new InjectionToken<boolean>('accommodation.seo');
我在组件中使用它
constructor(@Inject(IS_SEO_PAGE) private isSeo: boolean,
但是当我尝试将其注入测试时失败并出现错误
Can't resolve all parameters
这是测试:
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ TranslateModule.forRoot()],
declarations: [ StickyNavComponent ],
providers: [{ provide: IS_SEO_PAGE, useValue: true }],
schemas: [ NO_ERRORS_SCHEMA ],
}).compileComponents();
}));
it('should create', inject([IS_SEO_PAGE], (isSeo: boolean) => {
expect(component).toBeTruthy();
}));
答案 0 :(得分:0)
关闭InjectionToken的导入顺序非常重要,您希望在所有导入后导入令牌