测试使用Vutify的NuxtJS组件 [英] Testing NuxtJS Components that use Vuetify

查看:28
本文介绍了测试使用Vutify的NuxtJS组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在NuxtJS项目中使用JEST对使用Vutify的组件进行单元测试。当我想选择一个按钮(v-btn)时,jest输出以下内容:

 [vue-test-utils]: find did not return .v-btn, cannot call text() on empty Wrapper

我按照vutify的官方文档进行了单元测试。

// myComponent.vue

<template>
  <v-menu offset-y>
    <v-btn color="primary">
      myLabel
    </v-btn>
  </v-menu>
</template>

<script>
export default {
}
</script>

// myComponent.spec.js
import { createLocalVue, mount } from '@vue/test-utils'
import Vuetify from 'vuetify'
import MyComponent from '~/components/MyComponent'

describe('Index Switch', () => {
  const localVue = createLocalVue()
  let wrapper
  let vuetify

  beforeEach(() => {
    vuetify = new Vuetify()
    wrapper = mount(MyComponent, { localVue, vuetify })
  })

  it('should have index switch button', () => {
    const myButton = wrapper.find('.v-btn')
    expect(myButton.text()).toBe('myLabel')
  })
})

您知道这里出了什么问题吗?

推荐答案

适用于我

我希望您的问题也能解决

在测试文件中,如home.spec.test

const vuetify = new Vuetify()
Vue.use(Vuetify)
let localVue = createLocalVue()
localVue.use(vuetify)
"nuxt": "^2.14.6"
"@nuxtjs/vuetify": "^1.11.2",

这篇关于测试使用Vutify的NuxtJS组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆