Skip to content

Commit 2b989fb

Browse files
committed
chore: add test for nested v-model
1 parent 89f8450 commit 2b989fb

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

tests/setValue.spec.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,33 @@ describe('setValue', () => {
295295
template: '<div>{{ foo }} {{ bar }}</div>'
296296
})
297297

298+
const NestedInputComponentChild = defineComponent({
299+
props: ['modelValue', 'onUpdate:modelValue'],
300+
template: '<div>{{ modelValue }}</div>'
301+
})
302+
const NestedInputComponent = defineComponent({
303+
props: ['modelValue', 'onUpdate:modelValue'],
304+
template: '<NestedInputComponentChild v-model="modelValue" />',
305+
components: { NestedInputComponentChild }
306+
})
307+
298308
const Component = defineComponent({
299-
template:
300-
'<PlainInputComponent v-model="plain" /><MultiInputComponent v-model:foo="foo" v-model:bar="bar" />',
309+
template: `<PlainInputComponent v-model="plain" />
310+
<MultiInputComponent v-model:foo="foo" v-model:bar="bar" />
311+
<NestedInputComponent v-model="nested" />`,
301312
data() {
302313
return {
303314
plain: null,
304315
foo: null,
305-
bar: null
316+
bar: null,
317+
nested: null
306318
}
307319
},
308-
components: { PlainInputComponent, MultiInputComponent }
320+
components: {
321+
PlainInputComponent,
322+
MultiInputComponent,
323+
NestedInputComponent
324+
}
309325
})
310326

311327
describe('mount', () => {
@@ -324,6 +340,14 @@ describe('setValue', () => {
324340
expect(multiInput.text()).toContain('fooValue')
325341
expect(multiInput.text()).toContain('barValue')
326342
})
343+
344+
it('triggers a normal `v-model` on nested Vue Components', async () => {
345+
const wrapper = mount(Component)
346+
const nested = wrapper.findComponent(NestedInputComponent)
347+
const child = nested.findComponent(NestedInputComponentChild)
348+
await child.setValue('nested-value')
349+
expect(nested.text()).toContain('nested-value')
350+
})
327351
})
328352
describe('shallowMount', () => {
329353
it('triggers a normal `v-model` on a Vue Component', async () => {

0 commit comments

Comments
 (0)