我正在Jest尝试vue-test-utils测试子组件是否对$emit父组件中的事件做出反应。
VueJS test-utils 库提供了parentComponent在安装/浅安装组件时传递的选项。
一切都工作正常,除了即使我使用模拟的 Vuex 存储实例化组件,父组件也会抛出一个
类型错误:无法读取未定义的属性“状态”
this.$store.state.something.here在父组件中的一段代码上。
我怎样才能模拟 Vuex 商店呢?
组件安装如下所示:
const wrapper = shallowMount(ChildComponent, {
store,
localVue,
parentComponent: ParentComponent,
mocks: {
$t: msg => msg,
},
});
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题有什么想法吗?