首页 > 解决方案 > 测试具有 vuex 的 vue 组件

问题描述

我无法使用其中的 vuex 测试我的 vue 组件。
这是我的 mapGetters 之一

方法

listaSatelite() {
  if (this.getCropsSelected._id!=undefined) {
}}

这是我得到的错误:

Cannot read property '_modulesNamespaceMap' of undefined

计算的

 ...mapGetters("property",["getCropsSelected"]),

我的规格文件

import {shallowMount,createLocalVue} from '@vue/test-utils'
import Vuex from 'vuex'

import sateliteComponent from '@/components/satelite/listaSatelite.vue'
import sateliteStore from '@/core/modules/satelite/index.js'

var vueWithVuex = createLocalVue()
vueWithVuex.use(Vuex)
const store = new Vuex.Store({
    sateliteStore
})
describe('testes componente satelite', () => {

    test('instanciado', () => {
        const wrapper = shallowMount(sateliteComponent)
        console.log(wrapper)

    });
});


错误日志

TypeError: Cannot read property '_modulesNamespaceMap' of undefined

      119 |         },
      120 |         listaSatelite() {
    > 121 |           if (this.getCropsSelected._id!=undefined) {
          | ^
      122 |             this.listSatelite({
      123 |               startDate: this.getCropsSelected.startDate,
      124 |               endDate: this.getCropsSelected.endDate


在我的控制台中,它指向并显示错误在方法中,好像他无法导入或找到这个 getter

我不确定我做错了什么,欢迎任何帮助!如果有人有关于如何使用vuex测试vue的教程,但是测试组件,我在互联网上找到的是vuex本身的测试

标签: unit-testingvue.jsjestjsvuexvue-test-utils

解决方案


推荐阅读