doj*_*doj 4 javascript unit-testing vue.js jestjs
这是我的代码。请有人帮我找出错误。我正在使用 jest 来测试我使用 Vue 构建的前端。行 const localVue = createLocalVue(); 给出错误 TypeError: (0 , _testUtils.createLocalVue) 不是函数
import { createLocalVue,shallowMount } from '@vue/test-utils'
import Vuex from 'vuex'
import getters from '../../src/store/module/auth/getters.js'
import TheHeader from '@/components/layout/TheHeader.vue'
// const store = new Vuex.Store({
// state: {
// user:null,
// token:'',
// expiresIn:null,
// isUserLoggedIn:false,
// isAdminLoggedIn:false,
// }
// })
describe('TheHeader', () => {
const localVue = createLocalVue();
localVue.use(Vuex);
let store
let state
it('Checks whether the login is correctly displayed', () => {
const cmp = shallowMount(TheHeader, { store,localVue})
expect(cmp.name()).toMatch('TheHeader')
expect(cmp.vm.isLoggedIn()).toBe(false)
})
})
Run Code Online (Sandbox Code Playgroud)
createLocalVue在 的版本 2 中被删除@vue/test-utils,这解释了为什么它在您的示例中未定义。
要安装 Vue 插件(例如 Vuex),请使用global.plugins安装选项
要模拟实例 API(例如this.$store),请使用global.mocks安装选项
import Vuex from 'vuex'
import { shallowMount } from '@vue/test-utils'
import TheHeader from '@/components/TheHeader.vue'
const store = /* Vuex store */
const cmp = shallowMount(TheHeader, {
global: {
plugins: [Vuex],
// OR:
mocks: {
$store: store,
}
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5849 次 |
| 最近记录: |