|
1 | 1 | import { defineComponent, h } from 'vue'
|
2 |
| -import { mount } from '../src' |
| 2 | +import { mount, shallowMount } from '../src' |
3 | 3 | import ComponentWithInput from './components/ComponentWithInput.vue'
|
4 | 4 |
|
5 | 5 | describe('setValue', () => {
|
@@ -177,4 +177,64 @@ describe('setValue', () => {
|
177 | 177 | const fn = () => input.setValue('')
|
178 | 178 | expect(fn).toThrowError(message)
|
179 | 179 | })
|
| 180 | + |
| 181 | + describe('on component instance', () => { |
| 182 | + const PlainInputComponent = defineComponent({ |
| 183 | + props: ['modelValue'], |
| 184 | + template: '<div>{{ modelValue }}</div>' |
| 185 | + }) |
| 186 | + |
| 187 | + const MultiInputComponent = defineComponent({ |
| 188 | + props: ['foo', 'bar'], |
| 189 | + template: '<div>{{ foo }} {{ bar }}</div>' |
| 190 | + }) |
| 191 | + |
| 192 | + const Component = defineComponent({ |
| 193 | + template: |
| 194 | + '<PlainInputComponent v-model="plain" /><MultiInputComponent v-model:foo="foo" v-model:bar="bar" />', |
| 195 | + data() { |
| 196 | + return { |
| 197 | + plain: null, |
| 198 | + foo: null, |
| 199 | + bar: null |
| 200 | + } |
| 201 | + }, |
| 202 | + components: { PlainInputComponent, MultiInputComponent } |
| 203 | + }) |
| 204 | + |
| 205 | + describe('mount', () => { |
| 206 | + it('triggers a normal `v-model` on a Vue Component', async () => { |
| 207 | + const wrapper = mount(Component) |
| 208 | + const plain = wrapper.findComponent(PlainInputComponent) |
| 209 | + await plain.setValue('plain-value') |
| 210 | + expect(wrapper.text()).toContain('plain-value') |
| 211 | + }) |
| 212 | + |
| 213 | + it('triggers `v-model:parameter` style', async () => { |
| 214 | + const wrapper = mount(Component) |
| 215 | + const multiInput = wrapper.findComponent(MultiInputComponent) |
| 216 | + await multiInput.setValue('fooValue', 'foo') |
| 217 | + await multiInput.setValue('barValue', 'bar') |
| 218 | + expect(multiInput.text()).toContain('fooValue') |
| 219 | + expect(multiInput.text()).toContain('barValue') |
| 220 | + }) |
| 221 | + }) |
| 222 | + describe('shallowMount', () => { |
| 223 | + it('triggers a normal `v-model` on a Vue Component', async () => { |
| 224 | + const wrapper = shallowMount(Component) |
| 225 | + const plain = wrapper.findComponent(PlainInputComponent) |
| 226 | + await plain.setValue('plain-value') |
| 227 | + expect(wrapper.vm.plain).toEqual('plain-value') |
| 228 | + }) |
| 229 | + |
| 230 | + it('triggers `v-model:parameter` style', async () => { |
| 231 | + const wrapper = shallowMount(Component) |
| 232 | + const multiInput = wrapper.findComponent(MultiInputComponent) |
| 233 | + await multiInput.setValue('fooValue', 'foo') |
| 234 | + await multiInput.setValue('barValue', 'bar') |
| 235 | + expect(wrapper.vm.foo).toEqual('fooValue') |
| 236 | + expect(wrapper.vm.bar).toEqual('barValue') |
| 237 | + }) |
| 238 | + }) |
| 239 | + }) |
180 | 240 | })
|
0 commit comments