mock-vuex

A Mock version of Vuex to make unit testing easier
2,621 9
Install
npm install mock-vuex
Latest Version:1.0.1
Vue:2
License:MIT
Last Updated:May 2, 2019
Links: GitHub  ·  npm
Maintainer: jackmellis

mock-vuex

A Mock version of Vuex to make unit testing easier

Install

npm install mock-vuex --save-dev

Create with state

import mock from 'mock-vuex';
const store = mock({
  users : {
    user : { id : 1, name : 'user1' }
  }
});

Create with getters/actions/mutations/modules

import mock from 'mock-vuex';
const store = mock({
  modules : {
    users : {
      state : {
        user : { id : 1, name : 'user1' }
      },
      actions : {
        setUserName({state, commit}, payload){
          /* ... */
        }
      },
      mutations : {
        SET_USER_NAME(state, payload){
          /* ... */
        }
      }
    }
  }
});

Intercept commit/dispatch calls

store.when('dispatch', 'setUserName').return('success'); // calling store.dispatch('setUserName') will resolve with 'success'
store.expect('commit', 'SET_USER_NAME'); // adds a check to ensure a commit has been called

store.assert(); // throws if SET_USER_NAME has not been called

Full Documentation:
https://jackmellis.gitbooks.io/vuenit/content/store/introduction.html

Version History

Version Released Vue License
1.0.1 ^2.0.0 MIT
1.0.0 ^2.0.0 MIT
0.2.1 2.x MIT
0.2.0 2.x MIT
0.1.3 2.x MIT