Skip to content

Instantly share code, notes, and snippets.

@FunnyGhost
Last active September 12, 2019 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FunnyGhost/89d5e7c615628ca48874972b1d375e77 to your computer and use it in GitHub Desktop.
Save FunnyGhost/89d5e7c615628ca48874972b1d375e77 to your computer and use it in GitHub Desktop.
it('should fail if the backend returns an error 3 times in a row', done => {
let bubblesUpTheError = false;
serviceUnderTest.getFavoriteMovies().subscribe(() => {}, () => (bubblesUpTheError = true);
const req = http.expectOne(environment.favoriteUrl, 'expected to make an initial request');
expect(req.request.method).toEqual('GET');
req.flush('ERROR', { status: 500, statusText: 'Internal server error' });
const req2 = http.expectOne(environment.favoriteUrl, 'expected to make a second request');
expect(req2.request.method).toEqual('GET');
req2.flush('ERROR', { status: 500, statusText: 'Internal server error' });
const req3 = http.expectOne(environment.favoriteUrl, 'exected to make a third request');
expect(req3.request.method).toEqual('GET');
req3.flush('ERROR', { status: 500, statusText: 'Internal server error' });
expect(bubblesUpTheError).toBeTruthy();
http.verify();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment