Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.