我正在尝试为我的ApplicationStoreFacade
创建一个单元测试,并且只想运行至少一个测试方案,在该方案中,我可以确定商店已成功加载和初始化,但是我得到了一些依赖注入错误,因为我的ApplicationStore
扩展了EntityCollectionServiceBase<Application>
。导入和测试此ApplicationStoreFacade
的正确方法应该是什么?
application-store-facade
:
@Injectable()
export class ApplicationsStoreFacade extends EntityCollectionServiceBase<Application>{
applicationId$ = this.rootStore.applicationId$;
constructor(
elementsFactory: EntityCollectionServiceElementsFactory,
private rootStore: RootStore
) {
super(APPLICATION_ENTITY_NAME, elementsFactory);
}
...someMethods()
application-store.facade.spec.ts
:
import { APPLICATION_ENTITY_NAME } from './application-entity-name';
import { Application } from '@console/models';
import { EntityCollectionServiceElementsFactory, EntityCollectionServiceBase} from '@ngrx/data';
import { ApplicationsStoreFacade as ApplicationStore } from './applications-store.facade';
import { TestBed, inject } from '@angular/core/testing';
import { Inject } from '@angular/core';
class MockApplicationStore extends EntityCollectionServiceBase<Application> {
constructor(
@Inject(EntityCollectionServiceElementsFactory) elementsFactory: EntityCollectionServiceElementsFactory
) {
super(APPLICATION_ENTITY_NAME, elementsFactory);
}
}
describe('AppicationStore', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{ provide: ApplicationStore, useClass: MockApplicationStore },
]
});
});
it('should be created', inject([ApplicationStore], (applicationStore: ApplicationStore) => {
// expect(applicationStore).toBeDefined();
}));
});
我现在遇到的错误:
NullInjectorError: StaticInjectorError(DynamicTestModule)[ApplicationsStoreFacade -> EntityCollectionServiceElementsFactory]:
StaticInjectorError(Platform: core)[ApplicationsStoreFacade -> EntityCollectionServiceElementsFactory]:
NullInjectorError: No provider for EntityCollectionServiceElementsFactory!