-
-
Save dvallin/3f27b7eab8c8118ce83c7e38df6c2e5e 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
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