Skip to content

Commit dd3e1c9

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

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-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: 38 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,9 @@ describe('props', () => {
103103

104104
const wrapper = mount(component, {
105105
props: {
106-
modelValue: 1
106+
modelValue: 1,
107+
'onUpdate:modelValue': async (modelValue: number) =>
108+
wrapper.setProps({ modelValue })
107109
}
108110
})
109111

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

0 commit comments

Comments
 (0)