I'm testing Vue project with vue-test-utils and jest.
...
export default Vue.extend({
components: { MemoInputAndButton, DomeMemoLine },
data (): {
memoLineList: Array<IMemoLine>
} {
return {
memoLineList: []
}
},
computed: {
...mapGetters('fraudTransactionState', {
fraudTransactionDetail: FraudTransactionGetters.FraudTransactionDetail
})
},
created: async function () {
await this.setMemoLineList()
},
methods: {
...mapActions('fraudTransactionState', {
postFraudTransactionMemo: FraudTransactionActions.PostFraudTransactionMemo
}),
async onMemoInputted (input: string): Promise<void> {
await this.postMemo(input)
},
...
MemoTimelineSection.vue
It uses vuex in modules which is namespaced: true!
const localVue = createLocalVue()
localVue.use(ElementUI)
localVue.use(Vuex)
describe('MemoTimelineSection', () => {
const div = document.createElement('div')
div.id = 'root'
document.body.appendChild(div)
let wrapper
let getter = {
'FRAUD_STATICS': () => { },
'FRAUD_TRANSACTIONS': () => { },
'FRAUD_TRANSACTION_DETAIL': () => { }
}
let store
beforeEach(() => {
...
const div = document.createElement('div')
div.id = 'root'
document.body.appendChild(div)
...
store = new Vuex.Store({
modules: {
fraudTransactionState: {
getter,
namespaced: true
}
}
})
MemoTimelineSection.test.js
and actual vuex store is
export const store: StoreOptions<RootState> = {
state: {
...
},
mutations: {
...
},
actions: {},
modules: {
transfersStore,
fraudTransactionState
},
getters: {}
}
export default new Vuex.Store<RootState>(store)
index.ts
When I run the test file,
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'getters')
33 | console.log('run')
34 |
> 35 | export default new Vuex.Store<RootState>(store)
| ^
36 |
occurs.
When I remove mapGetters and mapActions from Vue code, this error doesn't appear so I think it's related to mapGetters or mapActions or something related to Vuex...
The other code, which doesn't use vuex store in modules(only in roots) and is composed of vue-class-component, is running correctly even though it also tests vuex.
How can I solve it? Thx in advance.