[Vuejs]-Vue.js (2.0) unit test issue

0👍

You’re on the right track – testResponse is undefined, because createShoppingList resolves with the return value of addNewShoppingList.then, which is unspecified, and defaults to undefined.

Should createShoppingList resolve with addNewShoppingList‘s response or the response from populateShoppingLists? If the former, return actionResponse from the handler:

return api.addNewShoppingList(shoppinglist).then((actionResponse) => {
  store.dispatch('populateShoppingLists')
  return actionResponse
});

As a side-note, because the actions you’re testing are promises, you can get rid of done in your tests by returning the actions directly:

it('should call commit method with POPULATE_SHOPPING_LIST string parameter', () => {
  // mocha will fail the test if the promise chain rejects or the expectation is not met
  return actions.populateShoppingLists(store).then(() => {
    expect(store.commit).to.have.been.calledWith(types.POPULATE_SHOPPING_LISTS, lists)
  })
})

Leave a comment