|
1 | 1 | import { defineComponent, h } from 'vue'
|
2 |
| - |
| 2 | +import WithProps from '../components/WithProps.vue' |
3 | 3 | import { mount } from '../../src'
|
4 | 4 |
|
5 |
| -test('mounting options - passes props', () => { |
6 |
| - const Component = defineComponent({ |
7 |
| - props: { |
8 |
| - message: { |
9 |
| - type: String, |
10 |
| - required: true |
| 5 | +describe('mountingOptions.props', () => { |
| 6 | + test('passes props', () => { |
| 7 | + const Component = defineComponent({ |
| 8 | + props: { |
| 9 | + message: { |
| 10 | + type: String, |
| 11 | + required: true |
| 12 | + } |
| 13 | + }, |
| 14 | + |
| 15 | + render() { |
| 16 | + return h('div', {}, `Message is ${this.message}`) |
11 | 17 | }
|
12 |
| - }, |
| 18 | + }) |
13 | 19 |
|
14 |
| - render() { |
15 |
| - return h('div', {}, `Message is ${this.message}`) |
16 |
| - } |
| 20 | + const wrapper = mount(Component, { |
| 21 | + props: { |
| 22 | + message: 'Hello' |
| 23 | + } |
| 24 | + }) |
| 25 | + expect(wrapper.text()).toBe('Message is Hello') |
| 26 | + }) |
| 27 | + |
| 28 | + test('assigns extra attributes on components', () => { |
| 29 | + const wrapper = mount(WithProps, { |
| 30 | + props: { |
| 31 | + class: 'HelloFromTheOtherSide', |
| 32 | + id: 'hello', |
| 33 | + disabled: true, |
| 34 | + msg: 'Hello World' |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + expect(wrapper.attributes()).toEqual({ |
| 39 | + class: 'HelloFromTheOtherSide', |
| 40 | + disabled: 'true', |
| 41 | + id: 'hello' |
| 42 | + }) |
| 43 | + |
| 44 | + expect(wrapper.props()).toEqual({ |
| 45 | + msg: 'Hello World' |
| 46 | + }) |
17 | 47 | })
|
18 | 48 |
|
19 |
| - const wrapper = mount(Component, { |
20 |
| - props: { |
21 |
| - message: 'Hello' |
| 49 | + test('assigns event listeners', async () => { |
| 50 | + const Component = { |
| 51 | + template: '<button @click="$emit(\'customEvent\', true)">Click</button>' |
22 | 52 | }
|
| 53 | + const onCustomEvent = jest.fn() |
| 54 | + const wrapper = mount(Component, { props: { onCustomEvent } }) |
| 55 | + const button = wrapper.find('button') |
| 56 | + await button.trigger('click') |
| 57 | + await button.trigger('click') |
| 58 | + await button.trigger('click') |
| 59 | + |
| 60 | + expect(onCustomEvent).toHaveBeenCalledTimes(3) |
23 | 61 | })
|
24 |
| - expect(wrapper.text()).toBe('Message is Hello') |
25 | 62 | })
|
0 commit comments