Created
October 6, 2020 02:54
-
-
Save Qarun-Qadir-Bissoondial/9b087f5276d5a44c869a30e7b6e541af to your computer and use it in GitHub Desktop.
Retry logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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