Skip to Content
Vue.js 2 Cookbook
book

Vue.js 2 Cookbook

by Andrea Passaglia
April 2017
Intermediate to advanced
454 pages
12h 51m
English
Packt Publishing
Content preview from Vue.js 2 Cookbook

Testing actions

Testing actions means testing that the action commits the expected mutations. We are not interested in the mutations themselves (not in unit tests at least) because they are already tested separately. We might, though, need to mock some dependencies.

To avoid any dependencies from Vue or Vuex (since we don't need them and they may pollute the tests), we create a new actions.js file inside the store directory. Install Axios with npm install axios. The actions.js file can look like the following:

import axios from 'axios'export const actions = {  downloadNew ({ commit }) {    axios.get('/myNewPosts')      .then(({ data }) => {        commit('ADD_ITEMS', data)      })  }}

To test for requirement number 2, we start by mocking the call to the server ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Vue.js 2

Learning Vue.js 2

Olga Filipova
Pro Vue.js 2

Pro Vue.js 2

Adam Freeman

Publisher Resources

ISBN: 9781786468093Supplemental Content