Skip to content

Instantly share code, notes, and snippets.

@dvallin
Created November 29, 2017 16:46
Show Gist options
  • Save dvallin/3f27b7eab8c8118ce83c7e38df6c2e5e to your computer and use it in GitHub Desktop.
Save dvallin/3f27b7eab8c8118ce83c7e38df6c2e5e to your computer and use it in GitHub Desktop.
import * as TasksApi from "../../src/api/tasks";
import axios from 'axios';
describe("tasks api", () => {
beforeEach(() => {
axios.get = jest.fn();
});
it("maps fetched tasks into response", () => {
const tasks = [];
axios.get.mockReturnValueOnce(Promise.resolve({data: tasks}));
return expect(TasksApi.fetchTasks()).resolves.toEqual(tasks);
});
it("hands errors down", () => {
const error = {};
axios.get.mockReturnValueOnce(Promise.reject(error));
return expect(TasksApi.fetchTasks()).rejects.toEqual(error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment