Я получаю ошибку как TypeError: Cannot read property 'dispatchEvent' of null
при тестировании компонента. вот мой код:
describe('SubSystemComponent', () => {
let component: SubSystemComponent;
let fixture: ComponentFixture<SubSystemComponent>;
let store: Store<ModelPFServices>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SubSystemComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [
HttpClientTestingModule,
FormsModule,
ReactiveFormsModule,
StoreModule.forRoot({}, { runtimeChecks: { strictStateImmutability: true, strictActionImmutability: true } }),
StoreModule.forFeature('pfservice', reducer),
EffectsModule.forRoot([]),
EffectsModule.forFeature([EffectsSubSystem])
]
})
.compileComponents();
store = TestBed.get(Store);
spyOn(store, 'dispatch').and.callThrough();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SubSystemComponent);
component = fixture.componentInstance;
spyOn(component.ssRemoved, 'emit');
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should delete a id', () => {
//this part shows error
const nativeElement = fixture.nativeElement;
const button = nativeElement.querySelector('.delete-item');
button.dispatchEvent(new MouseEvent('click'));
fixture.detectChanges();
});
});
что не так с моим кодом или как это исправить? кто-нибудь мне помочь?