I have written an angular test to test httpstatus 0 code returned when the service is not available. While running the test I am getting the following error. What is the possible issue here
Testing the interceptor class > making http calls > Adds a deliberate error code 0
Error: Expected undefined to equal 0.
Expected undefined to equal 'deliberate 0 error - Unknown Error'.
Error: Expected undefined to equal 'deliberate 0 error - Unknown Error'.
Unit Test
describe('making http calls', () => {
it('Adds a deliberate error code 0', inject([HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
spyOn(console, 'error');
const fakeUrl = "http://localhost:57973/";
const mockErrorResponse = { status: 0, statusText: 'deliberate 0 error - Unknown Error' };
const emsg = 'deliberate 0 error - Unknown Error';
let errResponse: any;
httpClient.get(fakeUrl).subscribe(
(response) => {
fail('deliberate 0 error - Unknown Error');
},
(error: HttpErrorResponse) => {
expect(error.status).toEqual(0, 'status');
expect(error.error).toEqual(emsg, 'message');
});
const req = httpMock.expectOne(fakeUrl);
httpMock.verify();
req.flush(emsg, { status: 0, statusText: 'Unknown Error' });
expect(routerSpy.navigate).toHaveBeenCalledWith(['offline']);
expect(console.error).toHaveBeenCalled();
}));
});
from Jasmine test fails Expected undefined to equal
No comments:
Post a Comment