两次浅表抛出错误Jest VueJs(Vuetify)

问题描述 投票:0回答:1

我正在将VueJs与Vuetify结合使用,我想测试我的组件:

import { shallowMount, createLocalVue } from '@vue/test-utils'
import UserRating from '@/views/dashboard/pages/User_Ratings.vue'
import BaseMaterialCard from '@/components/base/MaterialCard'
import Vuetify from 'vuetify'
let localVue

describe('user ratings Component Unit test', () => {
  let vuetify
  beforeEach(() => {
    localVue = createLocalVue()
    vuetify = new Vuetify()
    localVue.use(vuetify)
  })
  it('is a Vue instance', () => {
    const msg = 'new message'
    const wrapper = shallowMount(UserRating, {
      localVue,
      vuetify,
      sync: false,
      propsData: { msg },
    })

    expect(wrapper.isVueInstance()).toBeTruthy()
  })
  it('Checks the data-title', () => {
    const wrapper = shallowMount(UserRating, {
      localVue,
      vuetify,
      sync: false,
    })
    expect(wrapper.vm.title).toMatch('Users Reviews')
  })
  it('renders the reviews list', () => {
    const wrapper = shallowMount(UserRating, {
      localVue,
      vuetify,
      sync: false,
    })
    expect(wrapper.html()).toContain('v-simple-table')
  })
  it('check if child BaseMaterialCard exists', () => {
    const wrapper = shallowMount(UserRating, {
      sync: false,
    })
    expect(wrapper.contains(BaseMaterialCard)).toBe(true)
  })
})

我尝试了以下解决方案:Testing Vuetify (Vue.js) - Second call on mount throws error但是当我独立运行每个测试时,我没有问题,但是当我使用npm run test或开玩笑时,我的测试运行时出现错误:

console.error node_modules / vue / dist / vue.runtime.common.dev.js:1884TypeError:无法设置未定义的属性“ _error”console.error node_modules / vue / dist / vue.runtime.common.dev.js:621[Vue警告]:nextTick中的错误:“ TypeError:无法读取null的属性'createElement'”

我正在将VueJs与Vuetify一起使用,我想测试我的组件:从'@ vue / test-utils'import {{ ..

javascript unit-testing vue.js vuetify.js jest
1个回答
0
投票
import { shallowMount, createLocalVue } from '@vue/test-utils'
import UserRating from '@/views/dashboard/pages/User_Ratings.vue'
import BaseMaterialCard from '@/components/base/MaterialCard'
import Vuetify from 'vuetify'
const localVue = createLocalVue()
const vuetify = new Vuetify()
localVue.use(vuetify)

describe('user ratings Component Unit test', () => {
  it('is a Vue instance', () => {
    const msg = 'new message'
    const wrapper = shallowMount(UserRating, {
      sync: false,
      propsData: { msg },
    })

    expect(wrapper.isVueInstance()).toBeTruthy()
  })
  it('Checks the data-title', () => {
    const wrapper = shallowMount(UserRating, {
      sync: false,
    })
    expect(wrapper.vm.title).toMatch('Users Reviews')
  })
  it('renders the reviews list', () => {
    const wrapper = shallowMount(UserRating, {
      sync: false,
    })
    expect(wrapper.html()).toContain('v-simple-table')
  })
  it('check if child BaseMaterialCard exists', () => {
    const wrapper = shallowMount(UserRating, {
      sync: false,
    })
    expect(wrapper.contains(BaseMaterialCard)).toBe(true)
  })
})
© www.soinside.com 2019 - 2024. All rights reserved.