Skip to content

Instantly share code, notes, and snippets.

@dvallin
Created November 29, 2017 16:46
Show Gist options
  • Save dvallin/d6ed70e4cec436b6bbd326e6d6997d96 to your computer and use it in GitHub Desktop.
Save dvallin/d6ed70e4cec436b6bbd326e6d6997d96 to your computer and use it in GitHub Desktop.
describe("fetch tasks", () => {
beforeEach(() => {
TasksApi.fetchTasks = jest.fn();
});
it("calls success if api succeeds", async () => {
const context = mockContext(undefined);
const tasks = [];
TasksApi.fetchTasks.mockReturnValueOnce(
Promise.resolve(tasks)
);
await actions.fetchTasks(context, {
type: Actions.FetchTasks
});
expect(context.commit).toHaveBeenCalledWith({
type: Mutations.FetchTasksSucceeded,
tasks
});
});
it("calls error handling on error", async () => {
const context = mockContext(undefined);
const error = {info: "Server Out of Potatoes Exception"};
TasksApi.fetchTasks.mockReturnValueOnce(
Promise.reject(error)
);
await actions.fetchTasks(context, {
type: Actions.FetchTasks
});
expect(context.commit).toHaveBeenCalledWith({
type: Mutations.FetchTasksFailed,
error
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment