I'm trying to test a class that makes HTTP calls, mocking out the calls. I haven't actually set up my mock HTTP call yet so I would expect the test to fail, but it passes. How do I get the test to fail if the Observable doesn't return anything?
Here's my test:
describe('my service', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
MyService,
{ provide: XHRBackend, useClass: MockBackend }
]
});
});
it('should return a Candidate', async(inject([MyService], (service: MySerivce) => {
// given
const candidateId = 'test@test.com';
// when
service.getCandidate(candidateId).subscribe(candidate => {
expect(candidate.Id).toBe(candidateId);
// will have some other assertions here
});
})));
});
The MyService.getCandidate method does something like this:
public getCandidate(candidateId: string): Observable<Candidate> {
const url = '<my url>';
return this.http.get(url)
.map(this.parseCandidate);
}