gpt4 book ai didi

vue.js - @Vue/test-utilsshallowMount 为 vuetify 组件输出 "[Vue warn]: Unknown custom element"

转载 作者:行者123 更新时间:2023-12-03 19:16:26 26 4
gpt4 key购买 nike

我在 Vue 中的单元测试不仅针对 <v-col> 输出以下警告但是对于每个 vuetify 组件:

[Vue warn]: Unknown custom element: < v-col> - did you register the component correctly? For recursive components, make sure to provide the "name" option.



我创建了一个 localVue并添加 Vuetify ,但这似乎不起作用。这是我的测试用例:
import { shallowMount, createLocalVue } from '@vue/test-utils'
import expect from 'expect'
import ProjetoShow from '../../views/Projeto/ProjetoShow.vue'
import Vuetify from 'vuetify'

describe('ProjetoShow component', () => {
let wrapper
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuetify)
})

it('renders correctly', ()=> {
let vuetify = new Vuetify()
wrapper = shallowMount(ProjetoShow, {localVue, vuetify})
expect(wrapper.find('h2').text()).toContain('PROJETO')
})

})

我的软件包版本在 package.json
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.31",
"axios": "^0.19.0",
"cross-env": "^5.1",
"expect": "^24.9.0",
"jsdom": "^15.1.1",
"jsdom-global": "^3.0.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.13",
"mocha": "^6.2.0",
"mochapack": "^1.1.5",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.2",
"sass-loader": "^7.1.0",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"vue-router": "^3.1.3",
"vuetify": "^2.2.15",
"vuex": "^3.1.1"
},

最佳答案

Unit Testing 上的 Vuetify 文档中,他们声明 let vuetifydescribe块,然后在 beforeEach ,将该变​​量分配给 new Vuetify()
我没有看到您在测试代码的任何地方实际初始化 Vuetify,所以也许这就是这里所需要的。

关于vue.js - @Vue/test-utilsshallowMount 为 vuetify 组件输出 "[Vue warn]: Unknown custom element",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60345416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com