Skip to content

Instantly share code, notes, and snippets.

@dvallin
Created November 29, 2017 16:46
Show Gist options
  • Save dvallin/3c26c8852a3d1eb875c9a29023250507 to your computer and use it in GitHub Desktop.
Save dvallin/3c26c8852a3d1eb875c9a29023250507 to your computer and use it in GitHub Desktop.
beforeEach(() => {
axios.get = jest.fn();
axios.post = jest.fn();
});
describe("add task", () => {
it("maps added task into reponse", () => {
const task = new Task("task");
axios.post.mockReturnValueOnce(Promise.resolve({data: task}));
return expect(TasksApi.addTask("task")).resolves.toEqual(task);
});
it("hands error down", () => {
const error = {};
axios.post.mockReturnValueOnce(Promise.reject(error));
return expect(TasksApi.addTask("task")).rejects.toEqual(error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment