import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EventComponent } from './event.component';
import { NO_ERRORS_SCHEMA } from '@angular/compiler/src/core';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { of } from 'rxjs';
import { EventService } from '../../services/event.service';
describe('EventComponent', () => {
let component: EventComponent;
let fixture: ComponentFixture<EventComponent>;
let service: EventService;
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
{ provide: HttpClient, useValue: null },
{
provide: EventService,
useValue: {
getAttendees: () => {}
}
}
],
declarations: [EventComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EventComponent);
component = fixture.componentInstance;
service = TestBed.get(EventService);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should have a list of attendees set', () => {
const fakeAttendees = [{ name: 'FAKE_NAME', attending: false, guests: 0 }];
jest
.spyOn(service, 'getAttendees')
.mockImplementation(() => of(fakeAttendees));
component.ngOnInit();
component.attendees$.subscribe(attendees => {
expect(attendees).toEqual(fakeAttendees);
});
});
});
StackBlitz Link
Extras and Homework
These extra sections are for doing after the course or if you finish a section early. Please move onto the next section if doing this as a workshop when the instructor advises.
WARNING: Some of these extra sections will make it more difficult to copy and paste the code examples later on in the course.
You might need to apply the code snippet examples a little more carefully amongst any "extras section" code you may add. If you are up for some extra challenges these sections are for you.