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