Skip to content

Instantly share code, notes, and snippets.

@Qarun-Qadir-Bissoondial
Last active October 1, 2020 00:08
Show Gist options
  • Save Qarun-Qadir-Bissoondial/93bcc8c7657eb32f0b0df91c2e34a877 to your computer and use it in GitHub Desktop.
Save Qarun-Qadir-Bissoondial/93bcc8c7657eb32f0b0df91c2e34a877 to your computer and use it in GitHub Desktop.
it('createTodo should send a POST request and return the newly created item', (done) => {
const item: Todo = {
id: 2,
userId: 2,
title: 'Walk dog',
completed: false
};
service.createTodo(item).subscribe(
(data: Todo) => {
expect(data).toBeDefined();
expect(data).toEqual(item);
done()
},
(error) => {
fail(error.message)
}
);
const testRequest = httpMock.expectOne('https://jsonplaceholder.typicode.com/todos');
expect(testRequest.request.method).toBe('POST');
testRequest.flush(item);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment