|
| 1 | +/* eslint-disable no-undef */ |
| 2 | + |
| 3 | +import { defineComponent, PropType } from '@vue/composition-api' |
| 4 | +import { shallowMount } from '@vue/test-utils' |
| 5 | + |
| 6 | +describe('Prop merging test.', () => { |
| 7 | + it('Merge props should work properly.', () => { |
| 8 | + const Example = defineComponent({ |
| 9 | + props: { |
| 10 | + name: String as PropType<string>, |
| 11 | + age: Number as PropType<number> |
| 12 | + }, |
| 13 | + setup (props) { |
| 14 | + return () => ( |
| 15 | + <div>Name: {props.name}, age: {props.age}</div> |
| 16 | + ) |
| 17 | + } |
| 18 | + }) |
| 19 | + |
| 20 | + const wrapper = shallowMount(defineComponent({ |
| 21 | + setup () { |
| 22 | + const props = { |
| 23 | + name: 'John Smith', |
| 24 | + age: 100 |
| 25 | + } |
| 26 | + |
| 27 | + return () => ( |
| 28 | + <Example { ...props } /> |
| 29 | + ) |
| 30 | + } |
| 31 | + })) |
| 32 | + |
| 33 | + expect(wrapper.html()).toBe('<div>Name: John Smith, age: 100</div>') |
| 34 | + }) |
| 35 | + |
| 36 | + it('Merge props should work properly.', () => { |
| 37 | + const Example = defineComponent({ |
| 38 | + props: { |
| 39 | + name: String as PropType<string>, |
| 40 | + age: Number as PropType<number>, |
| 41 | + gender: String as PropType<string> |
| 42 | + }, |
| 43 | + setup (props) { |
| 44 | + return () => ( |
| 45 | + <div>Name: {props.name}, age: {props.age}, gender: {props.gender}</div> |
| 46 | + ) |
| 47 | + } |
| 48 | + }) |
| 49 | + |
| 50 | + const wrapper = shallowMount(defineComponent({ |
| 51 | + setup () { |
| 52 | + const props = { |
| 53 | + name: 'John Smith', |
| 54 | + age: 100 |
| 55 | + } |
| 56 | + |
| 57 | + return () => ( |
| 58 | + <Example { ...props } gender='male' /> |
| 59 | + ) |
| 60 | + } |
| 61 | + })) |
| 62 | + |
| 63 | + expect(wrapper.html()).toBe('<div>Name: John Smith, age: 100, gender: male</div>') |
| 64 | + }) |
| 65 | +}) |
0 commit comments