|
| 1 | +import { mount } from '../src' |
| 2 | +import { h } from 'vue' |
| 3 | +import Hello from './components/Hello.vue' |
| 4 | + |
| 5 | +describe('functionalComponents', () => { |
| 6 | + it('mounts a functional component', () => { |
| 7 | + const Foo = (props: { msg: string }) => |
| 8 | + h('div', { class: 'foo' }, props.msg) |
| 9 | + |
| 10 | + const wrapper = mount(Foo, { |
| 11 | + props: { |
| 12 | + msg: 'foo' |
| 13 | + } |
| 14 | + }) |
| 15 | + |
| 16 | + expect(wrapper.html()).toEqual('<div class="foo">foo</div>') |
| 17 | + }) |
| 18 | + |
| 19 | + it('renders the slots of a functional component', () => { |
| 20 | + const Foo = (props, { slots }) => h('div', { class: 'foo' }, slots) |
| 21 | + |
| 22 | + const wrapper = mount(Foo, { |
| 23 | + slots: { |
| 24 | + default: 'just text' |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + expect(wrapper.html()).toEqual('<div class="foo">just text</div>') |
| 29 | + }) |
| 30 | + |
| 31 | + it('asserts classes', () => { |
| 32 | + const Foo = (props, { slots }) => h('div', { class: 'foo' }, slots) |
| 33 | + |
| 34 | + const wrapper = mount(Foo, { |
| 35 | + attrs: { |
| 36 | + class: 'extra_classes' |
| 37 | + } |
| 38 | + }) |
| 39 | + |
| 40 | + expect(wrapper.classes()).toContain('extra_classes') |
| 41 | + expect(wrapper.classes()).toContain('foo') |
| 42 | + }) |
| 43 | + |
| 44 | + it('uses `find`', () => { |
| 45 | + const Foo = () => h('div', { class: 'foo' }, h(Hello)) |
| 46 | + const wrapper = mount(Foo) |
| 47 | + |
| 48 | + expect(wrapper.find('#root').exists()).toBe(true) |
| 49 | + }) |
| 50 | + |
| 51 | + it('uses `findComponent`', () => { |
| 52 | + const Foo = () => h('div', { class: 'foo' }, h(Hello)) |
| 53 | + const wrapper = mount(Foo) |
| 54 | + |
| 55 | + expect(wrapper.findComponent(Hello).exists()).toBe(true) |
| 56 | + }) |
| 57 | +}) |
0 commit comments