You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently having the issue, that some of my tests fail after updating from 2.0.0-rc.9 to 2.0.0-rc.10. When manually stubbing a component then I need to reassign the wrapper with findComponent to receive the correct values after making any update (e.g. emits or setProps).
After some checking I created a code snippet to test with. If you run the snippet with 2.0.0-rc.9 the tests passes. If running with 2.0.0-rc.10 the test "should test with stub" fails. In comparision with "should test with stub and reassign" there is only the reassign child = wrapper.findComponent({ name: 'ChildComponent' }) missing which is not necessary when testing without manually stub or with 2.0.0-rc.9.
import{defineComponent}from'vue'import{mount}from'@vue/test-utils'constChildComponent=defineComponent({name: 'ChildComponent',props: {modelValue: {type: String,required: true}},template: '<span>{{ modelValue }}</span>'})constMainComponent=defineComponent({components: { ChildComponent },props: {modelValue: {type: String,required: true}},template: '<ChildComponent v-model="modelValue" />'})describe('test stub',()=>{it('should test without stub',async()=>{constwrapper=mount(MainComponent,{props: {modelValue: '1'}})constchild=wrapper.findComponent({name: 'ChildComponent'})expect(child.props('modelValue')).toBe('1')awaitwrapper.setProps({modelValue: '2'})expect(child.props('modelValue')).toBe('2')})/** * Test stub component with reassign wrapper with findComponent * Works with rc.9 and rc.10 */it('should test with stub and reassign',async()=>{constwrapper=mount(MainComponent,{props: {modelValue: '1'},global: {stubs: {
ChildComponent
}}})letchild=wrapper.findComponent({name: 'ChildComponent'})expect(child.props('modelValue')).toBe('1')awaitwrapper.setProps({modelValue: '2'})child=wrapper.findComponent({name: 'ChildComponent'})expect(child.props('modelValue')).toBe('2')})/** * Test stub component without reassign wrapper with findComponent * Works with rc.9. Fails with rc.10 */it('should test with stub',async()=>{constwrapper=mount(MainComponent,{props: {modelValue: '1'},global: {stubs: {
ChildComponent
}}})constchild=wrapper.findComponent({name: 'ChildComponent'})expect(child.props('modelValue')).toBe('1')awaitwrapper.setProps({modelValue: '2'})expect(child.props('modelValue')).toBe('2')})})
The text was updated successfully, but these errors were encountered:
If you pass ChildComponent to components instead of stubs does it work?
As an aside, what exactly is the goal here? What is the use case to test if v-model works with a stubbed component? I understand this is a minimal reproduction, I'm not sure what the real world parallel for this use case is. I am still interesting in finding out if this change was intentional or not.
Hard to say which is "correct", since this is not something you can do in a real app, so I suppose we should match whatever VTU v1 does.
I am currently having the issue, that some of my tests fail after updating from
2.0.0-rc.9
to2.0.0-rc.10
. When manually stubbing a component then I need to reassign the wrapper withfindComponent
to receive the correct values after making any update (e.g. emits or setProps).After some checking I created a code snippet to test with. If you run the snippet with
2.0.0-rc.9
the tests passes. If running with2.0.0-rc.10
the test "should test with stub" fails. In comparision with "should test with stub and reassign" there is only the reassignchild = wrapper.findComponent({ name: 'ChildComponent' })
missing which is not necessary when testing without manually stub or with2.0.0-rc.9
.The text was updated successfully, but these errors were encountered: