【发布时间】:2018-12-31 04:17:04
【问题描述】:
我正在为 VueJS 组件编写单元测试,并参考了 Vue Test Utils Common Tips 的“应用全局插件和 Mixins”部分。我有一个依赖于 Vuex 存储的组件,因此出于我的目的,我将转置该部分下的示例是有道理的。
这是该组件的特定 .spec.js 文件的代码:
import { createLocalVue, mount } from '@vue/test-utils'
import AppFooter from '@/components/AppFooter/AppFooter'
import store from '@/store'
describe('AppFooter component', () => {
const localVue = createLocalVue()
localVue.use(store)
it('AppFooter should have header slot', () => {
const AppFooterComponent = mount(AppFooter, {
localVue
})
/* TODO: Replace with a more appropriate assertion */
expect(true).toEqual(true)
})
})
这非常忠实于上面链接中提供的示例。但是,我在运行测试套件时收到的错误如下:
我应该以不同的方式安装 Vue 商店吗?
【问题讨论】:
-
我相信你应该这样做:localVue.use(Vuex) 在顶部,然后在 localVue 之后将 store 作为参数传递给 mount()。
标签: unit-testing vue.js vuejs2 jestjs vuex