admin管理员组文章数量:1023744
I have the following test suite in Jest for a ponent. I have successfully written unit tests for several other ponents that follow a similar structure:
import { createLocalVue, mount } from '@vue/test-utils'
import Vuex from 'vuex'
import storeMock from '@mocks/store'
import RequestProposalsContainer from '@/ponents/RequestProposals/RequestProposalsContainer'
describe('ProviderComparison ponent', () => {
let localVue, store, wrapper, storeSetup
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
storeSetup = storeMock()
store = new Vuex.Store(storeSetup)
/* wrapper is undefined and I'm not sure why */
wrapper = mount(RequestProposalsContainer, {
localVue,
store
})
})
it('renders correct structure', () => {
/* undefined */
console.log('wrapper: ', wrapper)
})
})
By inspection, the ponent being mounted, the store, and localVue instance are well-defined.
I have the following test suite in Jest for a ponent. I have successfully written unit tests for several other ponents that follow a similar structure:
import { createLocalVue, mount } from '@vue/test-utils'
import Vuex from 'vuex'
import storeMock from '@mocks/store'
import RequestProposalsContainer from '@/ponents/RequestProposals/RequestProposalsContainer'
describe('ProviderComparison ponent', () => {
let localVue, store, wrapper, storeSetup
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
storeSetup = storeMock()
store = new Vuex.Store(storeSetup)
/* wrapper is undefined and I'm not sure why */
wrapper = mount(RequestProposalsContainer, {
localVue,
store
})
})
it('renders correct structure', () => {
/* undefined */
console.log('wrapper: ', wrapper)
})
})
By inspection, the ponent being mounted, the store, and localVue instance are well-defined.
Share Improve this question edited Oct 20, 2021 at 20:03 Riza Khan 3,1705 gold badges28 silver badges63 bronze badges asked Oct 1, 2018 at 21:03 Adam FreymillerAdam Freymiller 1,9398 gold badges28 silver badges53 bronze badges 4- Any clues from the console? Do you have a link to a GitHub repo that demonstrates the problem? – tony19 Commented Oct 2, 2018 at 0:42
- I took a look at more of the console errors and it turned out I needed to add necessary fields in the mock store, as well as add a stub for the router. Question has been resolved. – Adam Freymiller Commented Oct 2, 2018 at 20:05
- 3 @AdamFreymiller could you post your solution here and accept it? – whme Commented Oct 31, 2019 at 11:13
- @AdamFreymiller please share the solution – Andrius Solopovas Commented Mar 3, 2021 at 18:19
1 Answer
Reset to default 3I was in a similar situation where the wrapper
would e back undefined.
While testing, you have to give the ponent everything it needs to render.
It was (as @Adam Freymiller has already alluded to) that all the required values (props, store values, etc) were not set in the test, so the ponent would error out, much like how it would in a real life scenario.
I have the following test suite in Jest for a ponent. I have successfully written unit tests for several other ponents that follow a similar structure:
import { createLocalVue, mount } from '@vue/test-utils'
import Vuex from 'vuex'
import storeMock from '@mocks/store'
import RequestProposalsContainer from '@/ponents/RequestProposals/RequestProposalsContainer'
describe('ProviderComparison ponent', () => {
let localVue, store, wrapper, storeSetup
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
storeSetup = storeMock()
store = new Vuex.Store(storeSetup)
/* wrapper is undefined and I'm not sure why */
wrapper = mount(RequestProposalsContainer, {
localVue,
store
})
})
it('renders correct structure', () => {
/* undefined */
console.log('wrapper: ', wrapper)
})
})
By inspection, the ponent being mounted, the store, and localVue instance are well-defined.
I have the following test suite in Jest for a ponent. I have successfully written unit tests for several other ponents that follow a similar structure:
import { createLocalVue, mount } from '@vue/test-utils'
import Vuex from 'vuex'
import storeMock from '@mocks/store'
import RequestProposalsContainer from '@/ponents/RequestProposals/RequestProposalsContainer'
describe('ProviderComparison ponent', () => {
let localVue, store, wrapper, storeSetup
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
storeSetup = storeMock()
store = new Vuex.Store(storeSetup)
/* wrapper is undefined and I'm not sure why */
wrapper = mount(RequestProposalsContainer, {
localVue,
store
})
})
it('renders correct structure', () => {
/* undefined */
console.log('wrapper: ', wrapper)
})
})
By inspection, the ponent being mounted, the store, and localVue instance are well-defined.
Share Improve this question edited Oct 20, 2021 at 20:03 Riza Khan 3,1705 gold badges28 silver badges63 bronze badges asked Oct 1, 2018 at 21:03 Adam FreymillerAdam Freymiller 1,9398 gold badges28 silver badges53 bronze badges 4- Any clues from the console? Do you have a link to a GitHub repo that demonstrates the problem? – tony19 Commented Oct 2, 2018 at 0:42
- I took a look at more of the console errors and it turned out I needed to add necessary fields in the mock store, as well as add a stub for the router. Question has been resolved. – Adam Freymiller Commented Oct 2, 2018 at 20:05
- 3 @AdamFreymiller could you post your solution here and accept it? – whme Commented Oct 31, 2019 at 11:13
- @AdamFreymiller please share the solution – Andrius Solopovas Commented Mar 3, 2021 at 18:19
1 Answer
Reset to default 3I was in a similar situation where the wrapper
would e back undefined.
While testing, you have to give the ponent everything it needs to render.
It was (as @Adam Freymiller has already alluded to) that all the required values (props, store values, etc) were not set in the test, so the ponent would error out, much like how it would in a real life scenario.
本文标签: javascriptVuetestutils wrapper undefinedStack Overflow
版权声明:本文标题:javascript - Vue-test-utils wrapper undefined - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745545532a2155376.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论