Skip to content

Instantly share code, notes, and snippets.

@Qarun-Qadir-Bissoondial
Created October 6, 2020 02:54
Show Gist options
  • Save Qarun-Qadir-Bissoondial/9b087f5276d5a44c869a30e7b6e541af to your computer and use it in GitHub Desktop.
Save Qarun-Qadir-Bissoondial/9b087f5276d5a44c869a30e7b6e541af to your computer and use it in GitHub Desktop.
Retry logic
it('getSingleTodo should throw an error if 3 request attempts fail', (done) => {
const id = 1;
const errMessage = `Failed to fetch item with id ${id}`;
service.getSingleTodo(id).subscribe(
data => { fail('The request is supposed to throw an error') },
(error: string) => { expect(error).toEqual(errMessage); done(); },
);
const retryCount = 3;
for (let i = 0; i <= retryCount; i++) {
httpMock
.expectOne({url: 'https://jsonplaceholder.typicode.com/todos/1', method: 'GET'})
.flush({}, { status: 404, statusText: errMessage });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment