-
Notifications
You must be signed in to change notification settings - Fork 665
Closed
Labels
Description
Version
1.0.0-beta.10
Reproduction link
http://jsfiddle.net/m33w0o9p/2/
Steps to reproduce
For jest testing with vuex, if vuex contains both namespaced modules and global actions or states, it doesn't work. It will produce Cannot read property 'getters' of undefined
error.
Testing file
import { shallow, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import App from '@/App'
import auth from '../../../src/store/module/auth'
const localVue = createLocalVue()
localVue.use(Vuex)
describe('App', () => {
let actions
let store
beforeEach(() => {
actions = {
toggleDevice: jest.fn()
}
store = new Vuex.Store({
state: {},
modules: {
auth
},
actions
})
})
it('should have beforeMount hook', () => {
const wrapper = shallow(App, { store, localVue })
wrapper.setComputed({tokenExpired: true})
})
})
App.vue
export default {
name: 'app',
beforeMount () {
this.toggleDevice()
},
mounted () {
this.loadAuth()
},
computed: {
...mapGetters({
tokenExpired: 'auth/tokenExpired'
})
},
watch: {
tokenExpired () {
if (this.tokenExpired) {
this.$router.push('/login')
}
}
},
methods: mapActions({
toggleDevice: 'toggleDevice',
loadAuth: 'auth/loadAuth'
})
}
module/auth.js
const state = () => {
return {
tokenExpired: false
}
}
const getters = {
tokenExpired: state => state.tokenExpired
}
What is expected?
To pass the test
What is actually happening?
It doesn't compile, just suggesting Cannot read property 'getters' of undefined
I tried to make vuex store exactly like the one in production, it doesn't work.
I tried to combine the getters from the module to the global getters, it doesn't work either.
So I believe it is a bug
Etheryte, gk4m, alexander-elgin, RoelRoel, maresergiu and 11 more