Component 代码如下
export class BlogCategoryEditComponent implements OnInit {
constructor(
@Inject(NZ_MODAL_DATA)
private readonly nzModalData: BlogCategoryEditDto,
) {
this.category = this.nzModalData;
}
}
测试 spec 中下面的代码报错
beforeEach(() => {
fixture = TestBed.createComponent(BlogCategoryEditComponent);
TestBed.inject(BlogCategoryStore).refresh();
component = fixture.componentInstance;
fixture.detectChanges();
});
错误信息如下
NullInjectorError: No provider for InjectionToken NZ_MODAL_DATA!
请问如何解决这个问题?
通过下面的代码注册 NZ_MODAL_DATA 解决了
setupTestBed({
providers: [
{
provide: NZ_MODAL_DATA,
useValue: {},
},
]
});