Hi!
I'm trying to create a unit test for my app based in Vue and vue-cli with webpack template.
I read Vue documentation, vue-loader, vue-cli and vue-template/webpack (an more!). When I try to make a unit test for my component, I use this.
const Constructor = Vue.extend(MyComponent)
vm = new Constructor().$mount()
like Vue-template/webpack example and like Vue official
This work fine. but the pronlem is when my component has some props. I try to pass with this
const Constructor = Vue.extend(MyComponent)
vm = new Constructor({
myprop: 10
}).$mount()
And in my unit test, when I try to get this prop, I get undefined. How can I pass prop to my component in unit test?
I solve it with this
const Constructor = Vue.extend(MyComponent)
vm = new Constructor({
data: {
myProp: 10
}
}).$mount()
or this
const Constructor = Vue.extend(MyComponent)
vm = new Constructor({
propsData: {
myProp: 10
}
}).$mount()
You can use the next package vue-test-utils
Most helpful comment
I solve it with this
or this