donal
2018-04-16 991fcf9223a17ed77d31d5f87b13d759b533aed5
commit | author | age
90ac1e 1 import { shallow, createLocalVue, mount } from "@vue/test-utils";
b03f98 2 import Vuex from 'vuex';
991c76 3 import NewTodo from "@/components/NewTodo.vue";
D 4 // import { expect } from 'chai'
5
9d6970 6 import * as all from "../setup.js";
991c76 7
b03f98 8 const localVue = createLocalVue()
A 9
10 localVue.use(Vuex)
11
991c76 12 describe("NewTodo.vue", () => {
b03f98 13   let methods;
A 14   let store;
15
16   beforeEach(() => {
17     methods = {
18       newTodoAdded: jest.fn()
19     },
20     store = new Vuex.Store({
21       state: {},
22       methods
23     })
24   });
25
26   it("calls newTodoAdded() when keyup.enter hit.", () => {
27     // time to try and test some vuex stuff and see if the methods are called when expected.
28     const wrapper = shallow(NewTodo, { methods , localVue})
29     const input = wrapper.find(".md-input");
30     input.trigger('keyup.enter')
31     expect(methods.newTodoAdded).toHaveBeenCalled()
32   });
33
827ecd 34   it("does not call newTodoAdded() when keyup.space hit.", () => {
b03f98 35     // time to try and test some vuex stuff and see if the methods are called when expected.
A 36     const wrapper = shallow(NewTodo, { methods , localVue})
37     const input = wrapper.find(".md-input");
827ecd 38     input.trigger('keyup.space')
b03f98 39     expect(methods.newTodoAdded).not.toHaveBeenCalled()
A 40   });
41
991c76 42   it("renders props.placeholderMsg when passed", () => {
D 43     const msg = "Add a Todo";
44     const wrapper = shallow(NewTodo, {
45       propsData: { placeholderMsg: msg }
46     });
47     expect(wrapper.vm._props.placeholderMsg).toMatch(msg);
48   });
49
50   it("renders newTodo as empty string", () => {
51     const wrapper = shallow(NewTodo, {});
52     expect(wrapper.vm.newTodo).toMatch("");
53   });
54
b03f98 55   it("has the expected html structure", () => {
A 56     const wrapper = shallow(NewTodo);
57     expect(wrapper.element).toMatchSnapshot();
58   });
111f2f 59
90ac1e 60   // it("has the expected html structure", () => {
A 61   //   const wrapper = mount(NewTodo);
62   //   expect(wrapper.element).toMatchSnapshot();
63   // });
64
111f2f 65   // it("renders newTodo as test string ", () => {
A 66   //   const wrapper = shallow(NewTodo, {
67   //     propsData: { newTodo: "test string" }
68   //   });
69   //   expect(wrapper.vm.newTodo).toMatch("test string");
70   // });
b03f98 71 });