Skip to content

Instantly share code, notes, and snippets.

@Qarun-Qadir-Bissoondial
Last active October 1, 2020 03:40
Show Gist options
  • Save Qarun-Qadir-Bissoondial/d7e89c314e65a1b4dc939569989c7079 to your computer and use it in GitHub Desktop.
Save Qarun-Qadir-Bissoondial/d7e89c314e65a1b4dc939569989c7079 to your computer and use it in GitHub Desktop.
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