如何对衍生商店进行单元测试?

时间:2019-08-08 14:04:51

标签: angular ngrx

我正在尝试为我的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!

0 个答案:

没有答案