Skip to content

Commit 01cdd03

Browse files
committed
Test interceptor error handling
1 parent 9012cdc commit 01cdd03

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/app/http-interceptor.service.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,25 @@ describe('HttpInterceptorService', () => {
6969
pendingRequestsStatus
7070
.subscribe(
7171
next => expect(next).toBeTruthy(),
72-
error => console.log(error)
72+
error => expect(1).toBe(2)
7373
);
7474

7575
service.get('http://www.fake.url');
7676
})
7777
));
78+
79+
it('should fail correctly',
80+
inject([HttpInterceptorService, MockBackend], (service: HttpInterceptorService, backend: MockBackend) => {
81+
82+
const statusText = 'NOT FOUND';
83+
backend.connections.subscribe((connection: MockConnection) => {
84+
connection.mockError(new Response(new ResponseOptions({status: 404, statusText: statusText})) as any);
85+
});
86+
87+
service.get('http://www.fake.url').subscribe(
88+
next => expect(1).toBe(2),
89+
(error: Response) => expect(error.statusText).toBe(statusText)
90+
);
91+
})
92+
);
7893
});

0 commit comments

Comments
 (0)