Skip to content

Instantly share code, notes, and snippets.

@FunnyGhost
Created September 12, 2019 13:29
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/9c5bdb4cb286e3c43b8418d230e36be8 to your computer and use it in GitHub Desktop.
Save FunnyGhost/9c5bdb4cb286e3c43b8418d230e36be8 to your computer and use it in GitHub Desktop.
it('should return the list of favorite movies if the backend returns an error 2 times and the succeds', () => {
let favoriteMovies: Movie[] = [];
serviceUnderTest.getFavoriteMovies().subscribe(data => {
favoriteMovies = data;
});
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 req1 = http.expectOne(environment.favoriteUrl, 'expected to make a second request');
expect(req1.request.method).toEqual('GET');
req1.flush('ERROR', { status: 500, statusText: 'Internal server error' });
const req2 = http.expectOne(environment.favoriteUrl, 'exected to make a third request');
expect(req2.request.method).toEqual('GET');
req2.flush(moviesToUse);
expect(favoriteMovies).toEqual(moviesToUse);
http.verify();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment