Skip to content

Commit 5246e19

Browse files
committed
fix: revert automatic two way sync of v-model prop values
closes #440
1 parent 84f875f commit 5246e19

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/emit.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,4 @@ export const recordEvent = (
6464

6565
// Record the event message sent by the emit
6666
events[cid][event].push(args)
67-
68-
if (event.startsWith('update:')) {
69-
if (args.length !== 1) {
70-
throw new Error(
71-
'Two-way bound properties have to emit a single value. ' +
72-
args.length +
73-
' values given.'
74-
)
75-
}
76-
77-
vm.props[event.slice('update:'.length)] = args[0]
78-
}
7967
}

tests/props.spec.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mount } from '../src'
22
import WithProps from './components/WithProps.vue'
33
import Hello from './components/Hello.vue'
4-
import { defineComponent } from 'vue'
4+
import { defineComponent, h } from 'vue'
55

66
describe('props', () => {
77
it('returns a single prop applied to a component', () => {
@@ -103,7 +103,8 @@ describe('props', () => {
103103

104104
const wrapper = mount(component, {
105105
props: {
106-
modelValue: 1
106+
modelValue: 1,
107+
'onUpdate:modelValue': async (modelValue: number) => wrapper.setProps({ modelValue })
107108
}
108109
})
109110

@@ -185,4 +186,33 @@ describe('props', () => {
185186
foo: 'new value'
186187
})
187188
})
189+
190+
it('https://github.com/vuejs/vue-test-utils-next/issues/440', async () => {
191+
const Foo = defineComponent({
192+
name: 'Foo',
193+
props: {
194+
foo: String,
195+
},
196+
emits: ['update:foo'],
197+
setup (props, ctx) {
198+
return () => h('div', {
199+
onClick: () => {
200+
ctx.emit('update:foo', 'world')
201+
},
202+
}, props.foo)
203+
}
204+
})
205+
206+
const wrapper = mount(Foo, {
207+
props: {
208+
foo: 'hello'
209+
}
210+
})
211+
212+
expect(wrapper.text()).toEqual('hello')
213+
214+
await wrapper.trigger('click')
215+
216+
expect(wrapper.text()).toEqual('hello')
217+
})
188218
})

0 commit comments

Comments
 (0)