单元测试——引入Vuex

 1 // 基本信息
 2 import Vue from 'vue';
 3 import { mount , createLocalVue} from '@vue/test-utils'
 4 import "babel-polyfill";
 5 import Vuex from 'vuex'
 6 Vue.use(Vuex)
 7 import BasicInf from '@/components/model/basicInformation.vue'
 8 import RFF from '../../action/server.js';
 9 
10 describe('基本信息', function(){
11     let basic
12     let store; 
13     let vm
14     beforeEach(function() {
15         // 在本区块的每个测试用例之前执行
16         store = new Vuex.Store({
17             state: {
18             },
19             modules: {
20                 RFF: RFF,
21             }
22         })
23         Vue.prototype.$store = store  // 全局引用
24     });
25     afterEach(function() {
26         // 在本区块的每个测试用例之后执行 
27         basic.destroy(); //销毁组件
28     }); 
29     it('正确基本信息',  async()=>{
30         basic = mount(  BasicInf , {
31             propsData:{
32                 childSaleOrgId: '1,6',
33             }
34         });
35         vm = basic.vm;
36     });
37 })

组件用了vuex的mapActions触发,报了dispatch方法不存在的错误,这时就需要引入vuex触发相应的action了。

原文地址:https://www.cnblogs.com/daheiylx/p/14210115.html