admin管理员组文章数量:1410689
I spent one day solving undocumented issues regarding testing setup for Nuxt + Vuex + Vuetify with Jest.
I had issues like:
Unknown custom element: <nuxt-link> - When running jest unit tests
Cannot read property 'register' of undefined
[Vuetify] Multiple instances of Vue detected
I spent one day solving undocumented issues regarding testing setup for Nuxt + Vuex + Vuetify with Jest.
I had issues like:
Unknown custom element: <nuxt-link> - When running jest unit tests
Cannot read property 'register' of undefined
[Vuetify] Multiple instances of Vue detected
1 Answer
Reset to default 8After gathering multiple sources I've ended up with the following setup, which I'm documenting it here for anyone up for saving a day of headache.
Working setup:
// ./jest.config.js
module.exports = {
// ... other stuff
setupFilesAfterEnv: ['./test/jest.setup.js']
}
// ./test/jest.setup.js
import Vue from 'vue'
import Vuetify from 'vuetify'
import VueTestUtils from '@vue/test-utils'
Vue.use(Vuetify)
// Mock Nuxt ponents
VueTestUtils.config.stubs['nuxt'] = '<div />'
VueTestUtils.config.stubs['nuxt-link'] = '<a><slot /></a>'
VueTestUtils.config.stubs['no-ssr'] = '<span><slot /></span>'
// ./test/Header.test.js
import { mount, createLocalVue } from '@vue/test-utils'
import Vuetify from 'vuetify'
import Vuex from 'vuex'
import Header from '~/ponents/layout/Header'
const localVue = createLocalVue()
localVue.use(Vuex)
let wrapper
beforeEach(() => {
let vuetify = new Vuetify()
wrapper = mount(Header, {
store: new Vuex.Store({
state: { products: [] }
}),
localVue,
vuetify
})
})
afterEach(() => {
wrapper.destroy()
})
describe('Header', () => {
test('is fully functional', () => {
expect(wrapper.element).toMatchSnapshot()
})
})
本文标签: javascriptTesting setup for NuxtVuexVuetify with JestStack Overflow
版权声明:本文标题:javascript - Testing setup for Nuxt + Vuex + Vuetify with Jest - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744806718a2626192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论