|
| 1 | +import { mount, shallowMount } from '../src' |
| 2 | +import { defineComponent } from 'vue' |
| 3 | + |
| 4 | +const PlainInputComponent = defineComponent({ |
| 5 | + props: ['modelValue'], |
| 6 | + template: '<div>{{ modelValue }}</div>' |
| 7 | +}) |
| 8 | + |
| 9 | +const MultiInputComponent = defineComponent({ |
| 10 | + props: ['foo', 'bar'], |
| 11 | + template: '<div>{{ foo }} {{ bar }}</div>' |
| 12 | +}) |
| 13 | + |
| 14 | +const Component = defineComponent({ |
| 15 | + template: |
| 16 | + '<PlainInputComponent v-model="plain" /><MultiInputComponent v-model:foo="foo" v-model:bar="bar" />', |
| 17 | + data() { |
| 18 | + return { |
| 19 | + plain: null, |
| 20 | + foo: null, |
| 21 | + bar: null |
| 22 | + } |
| 23 | + }, |
| 24 | + components: { PlainInputComponent, MultiInputComponent } |
| 25 | +}) |
| 26 | + |
| 27 | +describe('setModelValue', () => { |
| 28 | + describe('mount', () => { |
| 29 | + it('triggers a normal `v-model` on a Vue Component', async () => { |
| 30 | + const wrapper = mount(Component) |
| 31 | + const plain = wrapper.findComponent(PlainInputComponent) |
| 32 | + await plain.setModelValue('plain-value') |
| 33 | + expect(wrapper.text()).toContain('plain-value') |
| 34 | + }) |
| 35 | + |
| 36 | + it('triggers `v-model:parameter` style', async () => { |
| 37 | + const wrapper = mount(Component) |
| 38 | + const multiInput = wrapper.findComponent(MultiInputComponent) |
| 39 | + await multiInput.setModelValue('fooValue', 'foo') |
| 40 | + await multiInput.setModelValue('barValue', 'bar') |
| 41 | + expect(multiInput.text()).toContain('fooValue') |
| 42 | + expect(multiInput.text()).toContain('barValue') |
| 43 | + }) |
| 44 | + }) |
| 45 | + describe('shallowMount', () => { |
| 46 | + it('triggers a normal `v-model` on a Vue Component', async () => { |
| 47 | + const wrapper = shallowMount(Component) |
| 48 | + const plain = wrapper.findComponent(PlainInputComponent) |
| 49 | + await plain.setModelValue('plain-value') |
| 50 | + expect(wrapper.vm.plain).toEqual('plain-value') |
| 51 | + }) |
| 52 | + |
| 53 | + it('triggers `v-model:parameter` style', async () => { |
| 54 | + const wrapper = shallowMount(Component) |
| 55 | + const multiInput = wrapper.findComponent(MultiInputComponent) |
| 56 | + await multiInput.setModelValue('fooValue', 'foo') |
| 57 | + await multiInput.setModelValue('barValue', 'bar') |
| 58 | + expect(wrapper.vm.foo).toEqual('fooValue') |
| 59 | + expect(wrapper.vm.bar).toEqual('barValue') |
| 60 | + }) |
| 61 | + }) |
| 62 | +}) |
0 commit comments