Last active
October 1, 2020 03:40
-
-
Save Qarun-Qadir-Bissoondial/d7e89c314e65a1b4dc939569989c7079 to your computer and use it in GitHub Desktop.
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
fdescribe('updateTodos', () => { | |
let displayErrorSpy: jasmine.Spy; | |
beforeEach(() => { | |
displayErrorSpy = spyOn(service, 'displayError'); | |
}) | |
it('should display an error message if the request is unauthorized', (done) => { | |
service | |
.updateTodo({ id: 1, userId: 1, title: 'Walk dog', completed: true }) | |
.subscribe( | |
(data => { | |
expect(data).toBeNull(); | |
expect(displayErrorSpy).toHaveBeenCalledWith('Unauthorized request'); | |
done(); | |
}), | |
(error: HttpErrorResponse) => { fail('The Observable is not supposed to fail') } | |
); | |
const testRequest = httpMock.expectOne('https://jsonplaceholder.typicode.com/todos/1'); | |
expect(testRequest.request.method).toBe('PUT'); | |
testRequest.flush(null, { status: 401, statusText: 'Unauthorized request'}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment