Commit 7feef84e authored by Winnie Hellmann's avatar Winnie Hellmann

Make stores export a createStore() which can be used in tests

parent 769c4a61
...@@ -37,12 +37,13 @@ import state from './state'; ...@@ -37,12 +37,13 @@ import state from './state';
Vue.use(Vuex); Vue.use(Vuex);
export default new Vuex.Store({ export const createStore = () => new Vuex.Store({
actions, actions,
getters, getters,
mutations, mutations,
state, state,
}); });
export default createStore();
``` ```
### `state.js` ### `state.js`
...@@ -320,10 +321,11 @@ In order to write unit tests for those components, we need to include the store ...@@ -320,10 +321,11 @@ In order to write unit tests for those components, we need to include the store
```javascript ```javascript
//component_spec.js //component_spec.js
import Vue from 'vue'; import Vue from 'vue';
import store from './store'; import { createStore } from './store';
import component from './component.vue' import component from './component.vue'
describe('component', () => { describe('component', () => {
let store;
let vm; let vm;
let Component; let Component;
...@@ -341,6 +343,8 @@ describe('component', () => { ...@@ -341,6 +343,8 @@ describe('component', () => {
age: '30', age: '30',
}; };
store = createStore();
// populate the store // populate the store
store.dispatch('addUser', user); store.dispatch('addUser', user);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment