donal
2018-04-16 a663e942df46f05082f504c7d1d8c29d3af941d3
ADD more tests for the store
3 files modified
72 ■■■■■ changed files
src/store/actions.js 5 ●●●●● patch | view | raw | blame | history
tests/unit/javascript/actions.spec.js 55 ●●●● patch | view | raw | blame | history
tests/unit/javascript/store.spec.js 12 ●●●●● patch | view | raw | blame | history
src/store/actions.js
@@ -91,9 +91,10 @@
    }
    //  2 return array of promises and resolve all
  },
  updateTodo({ commit, state }, id) {
  /* eslint: ignore */
  updateTodo({ commit, state }, { id, important }) {
    let i = state.todos.findIndex(todo => todo._id === id);
    // todo - add back end
    // console.info("BLAB HALASD", state);
    return axios
      .put(config.todoEndpoint + "/" + state.todos[i]._id, state.todos[i])
      .then(data => {
tests/unit/javascript/actions.spec.js
@@ -5,8 +5,8 @@
import sinon from "sinon";
const todos = [
  { id: 1, title: "learn testing", completed: true },
  { id: 2, title: "learn testing 2", completed: false }
  { _id: 1, title: "learn testing", completed: true },
  { _id: 2, title: "learn testing 2", completed: false }
];
let state;
@@ -101,7 +101,7 @@
});
/* 
    updateTodo({ commit, state }, id) {
  updateTodo({ commit, state }, { id, important }) {
    let i = state.todos.findIndex(todo => todo._id === id);
    // todo - add back end
    return axios
@@ -112,28 +112,27 @@
      });
  }
*/
// describe("updateTodo", () => {
//   beforeEach(() => {
//     state = {};
//     let mock = new MockAdapter(axios);
//     mock.onPut(/http:\/\/localhost:9000\/api\/todos\/.*/, {}).reply(200, todos);
//   });
//   it("should call commit to the mutation function once", done => {
//     const commit = sinon.spy();
//     state.newTodo = "Learn some mocking";
//     actions.updateTodo({ commit, state }).then(() => {
//       // console.log(commit)
//       expect(commit.calledOnce).toBe(true);
//       done();
//     });
//   });
//   it("should call MARK_TODO_COMPLETED", done => {
//     const commit = sinon.spy();
//     state.newTodo = "Learn some mocking";
//     actions.updateTodo({ commit, state }).then(() => {
//       // console.log(commit.firstCall.args[0])
//       expect(commit.firstCall.args[0]).toBe("ADD_TODO");
//       done();
//     });
//   });
// });
describe("updateTodo", () => {
  beforeEach(() => {
    state = {};
    let mock = new MockAdapter(axios);
    mock.onPut("http://localhost:9000/api/todos/1").reply(200, todos);
  });
  it("should call commit to the mutation function once", done => {
    const commit = sinon.spy();
    state.todos = todos;
    actions.updateTodo({ commit, state }, { id: 1 }).then(() => {
      expect(commit.calledOnce).toBe(true);
      done();
    });
  });
  it("should call MARK_TODO_COMPLETED", done => {
    const commit = sinon.spy();
    state.todos = todos;
    actions.updateTodo({ commit, state }, { id: 1 }).then(() => {
      // console.log(commit.firstCall.args[0])
      expect(commit.firstCall.args[0]).toBe("MARK_TODO_COMPLETED");
      done();
    });
  });
});
tests/unit/javascript/store.spec.js
@@ -11,18 +11,6 @@
  it("should have loading true by default", () => {
    expect(store.state.loading).toBe(true);
  });
  /*
  state: {
    loading: true,
    todos: [],
    newTodo: ""
  },
  getters: {
    newTodo: state => state.newTodo,
    todos: state => state.todos
  },
  */
});
describe("state getters", () => {