Skip to content

Instantly share code, notes, and snippets.

@achhunna
Last active May 5, 2019 01:58
Show Gist options
  • Save achhunna/1e379a05197aa980db967ac1616b3638 to your computer and use it in GitHub Desktop.
Save achhunna/1e379a05197aa980db967ac1616b3638 to your computer and use it in GitHub Desktop.
Jest test template with Vuex
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import Component from './component';
let wrapper;
let store;
let actions;
let mutations;
let state;
const localVue = createLocalVue();
localVue.use(Vuex);
beforeEach(() => {
actions = {
someAction: jest.fn()
};
mutations = {
someMutation: jest.fn()
};
state = {
key: {}
};
store = new Vuex.Store({
actions,
mutations,
state,
});
wrapper = shallowMount(Component, {
propsData: {},
mocks: {},
stubs: {},
methods: {},
store,
localVue,
});
});
afterEach(() => {
wrapper.destroy();
});
describe('Component', () => {
test('is a Vue instance', () => {
expect(wrapper.isVueInstance).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment