21. Test an effect
In this section we will use marble tests to test our effects observable streams.
1. Fix broken EventComponent test
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EventComponent } from './event.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EventService } from '../../services/event.service';
import { Store } from '@ngrx/store';
describe('EventComponent', () => {
let component: EventComponent;
let fixture: ComponentFixture<EventComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
{
provide: EventService,
useValue: {
getAttendees: () => {},
}
},
{
provide: Store,
useValue: {
pipe: () => {},
dispatch: () => {}
}
}
],
declarations: [EventComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EventComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
2. Install jest-marbles
3. Add effect spec file
StackBlitz Link
Extras and Homework
Read more about testing observables
Last updated