Test with Angular TestBed
beforeEach(() => {
NgStateTestBed.setTestEnvironment(new ImmerDataStrategy());
NgStateTestBed.strictActionsCheck = false;
const initialState = { todos: [{...}] };
NgStateTestBed.createActions(TodosStateActions, initialState, ['todos']);
TestBed.configureTestingModule({
declarations: [TodosComponent, TodoDescriptionComponent]
});
fixture = TestBed.createComponent(TodosComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});it('should change child description on button click', () => {
expect(fixture.nativeElement.querySelector('div.description').textContent).toEqual('test description');
const button = fixture.debugElement.query(By.css('.button'));
button.triggerEventHandler('click', null);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div.description').textContent).toEqual('changed description');
});Last updated