Last active
October 12, 2020 02:26
-
-
Save oladimillion/4c9e2a406051b011813ee45816ee6aaf to your computer and use it in GitHub Desktop.
Fix for Vuex mocking not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/vuejs/vue-test-utils/issues/116#issuecomment-521366881 | |
``` | |
-- MyComponent.spec.js -- | |
import { shallowMount } from '@vue/test-utils' | |
import store from '@/store' | |
import router from '@/router' | |
import MyComponent from '@/components/MyComponent' | |
describe('MyComponent', () => { | |
const wrapper = shallowMount(MyComponent, { | |
router, | |
store, | |
}) | |
it('render without crashing', () => { | |
... | |
}) | |
}) | |
``` | |
``` | |
-- store.js -- | |
import Vue from 'vue' | |
import Vuex from 'vuex' | |
const test = { | |
namespaced: true, | |
state: { ... }, | |
getters: { ... }, | |
actions: { ... }, | |
mutations: { ... }, | |
} | |
Vue.use(Vuex) | |
const debug = process.env.NODE_ENV !== 'production' | |
export default new Vuex.Store({ | |
modules: { | |
test, | |
}, | |
strict: debug, | |
}); | |
``` | |
``` | |
-- router.js -- | |
import Vue from 'vue' | |
import VueRouter from 'vue-router' | |
import MyComponent from '@/components/MyComponent' | |
const routes = [ | |
{ path: '/', name: 'My Component', component: MyComponent }, | |
] | |
Vue.use(VueRouter) | |
export default new VueRouter({ | |
mode: 'history', | |
routes, | |
}) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment