Created
September 11, 2019 16:06
-
-
Save djirdehh/3faf8640ad49c1952aa8a65ffefe9171 to your computer and use it in GitHub Desktop.
Full solution for 06 - Testing - Full Day of Vue.js Workshop
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 { shallowMount } from "@vue/test-utils"; | |
import App from "@/App.vue"; | |
describe("App", () => { | |
let wrapper; | |
beforeEach(() => { | |
wrapper = shallowMount(App); | |
}); | |
it("should render correct initial content", () => { | |
expect(wrapper.find(".title").text()).toBe("todos"); | |
expect( | |
wrapper.find(".new-todo").element.placeholder | |
).toBe("What needs to be done?"); | |
}); | |
it("should set correct default data", () => { | |
expect(wrapper.vm.todos).toEqual([]); | |
expect(wrapper.vm.newTodo).toEqual(""); | |
}); | |
describe("the user populates the text input field", () => { | |
let inputField; | |
beforeEach(() => { | |
inputField = wrapper.find(".new-todo"); | |
inputField.element.value = "New Todo"; | |
inputField.trigger("input"); | |
}); | |
it("should update the 'newTodo' data property", () => { | |
expect(wrapper.vm.newTodo).toEqual("New Todo"); | |
}); | |
describe("and presses Enter", () => { | |
it("should add a new todo to the 'todos' array", () => { | |
inputField.trigger("keyup.enter"); | |
expect(wrapper.vm.todos).toEqual(["New Todo"]); | |
}); | |
}); | |
describe("and presses Enter and then removes the todo item", () => { | |
it("should have the new todo removed from the 'todos' array", () => { | |
inputField.trigger("keyup.enter"); | |
const removeIcon = wrapper.find(".destroy"); | |
removeIcon.trigger("click"); | |
expect(wrapper.vm.todos).toEqual([]); | |
}); | |
}); | |
}); | |
describe("the user clicks the 'Remove all' label", () => { | |
it("should remove all todos from the 'todos' data property", () => { | |
wrapper.setData({ | |
todos: ["Todo #1", "Todo #2", "Todo #3"] | |
}); | |
const removeAllButton = wrapper.find( | |
".clear-completed" | |
); | |
removeAllButton.trigger("click"); | |
expect(wrapper.vm.todos).toEqual([]); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment