我想测试我的 ngrx 数据服务:
@Injectable({
providedIn: 'root',
})
export class PostsService extends EntityCollectionServiceBase<Post>{
constructor(serviceElemtsFactory: EntityCollectionServiceElementsFactory) {
super('Post', serviceElemtsFactory);
}
}
到目前为止,我已经定义了以下测试类:
describe('PatientService', () => {
let service: PostsService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
EffectsModule.forRoot([]),
StoreModule.forRoot({}),
EntityDataModule.forRoot(entityConfig)
],
providers: [
{
provide: EntityCollectionServiceElementsFactory,
useValue: MockService(EntityCollectionServiceElementsFactory),
},
PostsService,
],
}).compileComponents();
service = TestBed.inject(PostsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
但我收到错误:
TypeError: 无法解构 'serviceElementsFactory.create(...)' 的属性 'dispatcher',因为它未定义。
如何正确修复我的测试?