БЛОК ИСПЫТАНИЯ JASMINE @NGRX/DATA
Я пытаюсь написать модульные тесты для своего проекта angular, используя @ngrx/data! Я получаю ошибки
Ошибка: неожиданное значение EntityCollectionServiceBase, импортированное модулем DynamicTestModule. Добавьте аннотацию @NgModule.
NullInjectorError: R3InjectorError(DynamicTestModule)[CalendarService -> EntityCollectionServiceElementsFactory -> EntityCollectionServiceElementsFactory]: NullInjectorError: No provider for EntityCollectionServiceElement
SERVICE
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Appointment } from '../models/appointment';
import {
EntityCollectionServiceBase,
EntityCollectionServiceElementsFactory
} from '@ngrx/data';
@Injectable({
providedIn: 'root'
})
export class CalendarService extends EntityCollectionServiceBase<Appointment> {
calendar$: Observable<Appointment>;
constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {
super('Appointment', serviceElementsFactory);
}
}
TEST FILE
import { TestBed, async } from '@angular/core/testing';
import { StoreModule, Store } from '@ngrx/store';
import { CalendarService } from './calendar.service';
import { EntityDataModule } from '@ngrx/data';
import { entityConfig } from '../entity-metadata';
import {
EntityCollectionServiceBase,
EntityCollectionServiceElementsFactory
} from '@ngrx/data';
describe('CalendarService', () => {
let service: CalendarService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({}),
EntityCollectionServiceBase,
EntityCollectionServiceElementsFactory
],
declarations: [],
providers: [EntityDataModule.forRoot(entityConfig)]
}).compileComponents();
service = TestBed.inject(CalendarService);
}));
it('should be created', () => {
expect(service).toBeTruthy();
});
});
1 ответ
Вот моя установка
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
EntityDataModule.forRoot({
entityMetadata
})
],
providers: [
MyService,
{ provide: EntityCacheEffects, useValue: {} },
{ provide: EntityDataService, useValue: null }
]
});
await TestBed.compileComponents();
});