Skip to content

Commit

Permalink
chore: add test for nested v-model
Browse files Browse the repository at this point in the history
  • Loading branch information
tharvik committed Jul 9, 2024
1 parent 89f8450 commit 2b989fb
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/setValue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,33 @@ describe('setValue', () => {
template: '<div>{{ foo }} {{ bar }}</div>'
})

const NestedInputComponentChild = defineComponent({
props: ['modelValue', 'onUpdate:modelValue'],
template: '<div>{{ modelValue }}</div>'
})
const NestedInputComponent = defineComponent({
props: ['modelValue', 'onUpdate:modelValue'],
template: '<NestedInputComponentChild v-model="modelValue" />',
components: { NestedInputComponentChild }
})

const Component = defineComponent({
template:
'<PlainInputComponent v-model="plain" /><MultiInputComponent v-model:foo="foo" v-model:bar="bar" />',
template: `<PlainInputComponent v-model="plain" />
<MultiInputComponent v-model:foo="foo" v-model:bar="bar" />
<NestedInputComponent v-model="nested" />`,
data() {
return {
plain: null,
foo: null,
bar: null
bar: null,
nested: null
}
},
components: { PlainInputComponent, MultiInputComponent }
components: {
PlainInputComponent,
MultiInputComponent,
NestedInputComponent
}
})

describe('mount', () => {
Expand All @@ -324,6 +340,14 @@ describe('setValue', () => {
expect(multiInput.text()).toContain('fooValue')
expect(multiInput.text()).toContain('barValue')
})

it('triggers a normal `v-model` on nested Vue Components', async () => {
const wrapper = mount(Component)
const nested = wrapper.findComponent(NestedInputComponent)
const child = nested.findComponent(NestedInputComponentChild)
await child.setValue('nested-value')
expect(nested.text()).toContain('nested-value')

Check failure on line 349 in tests/setValue.spec.ts

View workflow job for this annotation

GitHub Actions / build (18)

tests/setValue.spec.ts > setValue > on component instance > mount > triggers a normal `v-model` on nested Vue Components

AssertionError: expected '' to contain 'nested-value' - Expected + Received - nested-value ❯ tests/setValue.spec.ts:349:31

Check failure on line 349 in tests/setValue.spec.ts

View workflow job for this annotation

GitHub Actions / build (20)

tests/setValue.spec.ts > setValue > on component instance > mount > triggers a normal `v-model` on nested Vue Components

AssertionError: expected '' to contain 'nested-value' - Expected + Received - nested-value ❯ tests/setValue.spec.ts:349:31
})
})
describe('shallowMount', () => {
it('triggers a normal `v-model` on a Vue Component', async () => {
Expand Down

0 comments on commit 2b989fb

Please sign in to comment.