Skip to content

Instantly share code, notes, and snippets.

@lusarz
Created April 6, 2019 08:26
Show Gist options
  • Save lusarz/5a4c736840316ad1b268978fcbdfd3f7 to your computer and use it in GitHub Desktop.
Save lusarz/5a4c736840316ad1b268978fcbdfd3f7 to your computer and use it in GitHub Desktop.
Build vuex store in unit tests
import { shallowMount } from '@vue/test-utils';
import Vuex from 'vuex';
import Form from 'components/form';
export function buildStores (stores) {
const modules = {};
stores.forEach(config => {
modules[config.name] = {
namespaced: true,
state: config.state || {},
getters: config.getters || {},
actions: config.actions || {},
mutations: config.mutations || {}
};
});
return new Vuex.Store({ modules });
}
// Potem w testach
const wrapper = shallowMount(Form, {
store: buildStores([{
name: 'subscriptions',
getters: {
subscriber: () => ({ name: 'xyz', saml: {} }),
termsAccepted: () => true
}
}])
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment