Skip to content

Commit

Permalink
fix: revert automatic two way sync of v-model prop values
Browse files Browse the repository at this point in the history
closes vuejs#440
  • Loading branch information
nekosaur committed Mar 13, 2021
1 parent 84f875f commit 5246e19
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,4 @@ export const recordEvent = (

// Record the event message sent by the emit
events[cid][event].push(args)

if (event.startsWith('update:')) {
if (args.length !== 1) {
throw new Error(
'Two-way bound properties have to emit a single value. ' +
args.length +
' values given.'
)
}

vm.props[event.slice('update:'.length)] = args[0]
}
}
34 changes: 32 additions & 2 deletions tests/props.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount } from '../src'
import WithProps from './components/WithProps.vue'
import Hello from './components/Hello.vue'
import { defineComponent } from 'vue'
import { defineComponent, h } from 'vue'

describe('props', () => {
it('returns a single prop applied to a component', () => {
Expand Down Expand Up @@ -103,7 +103,8 @@ describe('props', () => {

const wrapper = mount(component, {
props: {
modelValue: 1
modelValue: 1,
'onUpdate:modelValue': async (modelValue: number) => wrapper.setProps({ modelValue })
}
})

Expand Down Expand Up @@ -185,4 +186,33 @@ describe('props', () => {
foo: 'new value'
})
})

it('https://github.com/vuejs/vue-test-utils-next/issues/440', async () => {
const Foo = defineComponent({
name: 'Foo',
props: {
foo: String,
},
emits: ['update:foo'],
setup (props, ctx) {
return () => h('div', {
onClick: () => {
ctx.emit('update:foo', 'world')
},
}, props.foo)
}
})

const wrapper = mount(Foo, {
props: {
foo: 'hello'
}
})

expect(wrapper.text()).toEqual('hello')

await wrapper.trigger('click')

expect(wrapper.text()).toEqual('hello')
})
})

0 comments on commit 5246e19

Please sign in to comment.