Skip to content

Instantly share code, notes, and snippets.

@Qarun-Qadir-Bissoondial
Created October 1, 2020 02:07
Show Gist options
  • Save Qarun-Qadir-Bissoondial/ab303fa5fbca7abe65a089bf97099065 to your computer and use it in GitHub Desktop.
Save Qarun-Qadir-Bissoondial/ab303fa5fbca7abe65a089bf97099065 to your computer and use it in GitHub Desktop.
Testing 500 status response
fdescribe('getAllTodos', () => {
it('should return an empty array if an Interal Server Error occurs', (done) => {
service.getAllTodos().subscribe(
(data: Todo[]) => {
expect(data).toBeDefined();
expect(Array.isArray(data)).toBe(true);
expect(data.length).toBe(0);
done()
},
(error: HttpErrorResponse) => { fail('The request was supposed to return an empty array') }
);
const testRequest = httpMock.expectOne('https://jsonplaceholder.typicode.com/todos');
expect(testRequest.request.method).toBe('GET');
testRequest.flush({}, { status: 500, statusText: 'Internal Server Error' });
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment