Skip to content

Instantly share code, notes, and snippets.

@dvallin
Created November 29, 2017 16:46
Show Gist options
  • Save dvallin/613e2a13d03e310e2c636f767b65e308 to your computer and use it in GitHub Desktop.
Save dvallin/613e2a13d03e310e2c636f767b65e308 to your computer and use it in GitHub Desktop.
describe("actions", () => {
const mockContext = (foundTask: Task) => {
return {
getters: { taskByTitle:(s) => foundTask },
commit: jest.fn()
};
};
it("adds tasks if they cannot be found", () => {
const context = mockContext(undefined);
const taskTitle = "title";
actions.addTask(context, {
type: Actions.AddTask,
title: taskTitle
});
expect(context.commit).toHaveBeenCalledWith({
type: Mutations.TaskAdded,
task: new Task(taskTitle)
});
});
it("does not add tasks if they can be found", () => {
const taskTitle = "title";
const context = mockContext(new Task(taskTitle));
actions.addTask(context, {
type: Actions.AddTask,
title: taskTitle
});
expect(context.commit).toHaveBeenCalledTimes(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment