|
| 1 | +import { mount } from '../src' |
| 2 | +import { defineComponent, h } from 'vue' |
| 3 | + |
| 4 | +describe('findAllComponentsInSubTree', () => { |
| 5 | + it('finds all components', () => { |
| 6 | + const compB = defineComponent({ |
| 7 | + name: 'compB', |
| 8 | + render: () => h('div', { class: 'B' }, 'TextB') |
| 9 | + }) |
| 10 | + const compA = defineComponent({ |
| 11 | + name: 'compA', |
| 12 | + template: '<div><slot /></div>' |
| 13 | + }) |
| 14 | + const starter = defineComponent({ |
| 15 | + name: 'starter', |
| 16 | + template: '<comp-a><comp-b /><comp-b /><comp-b /></comp-a>', |
| 17 | + components: { compA, compB } |
| 18 | + }) |
| 19 | + const App = defineComponent({ |
| 20 | + name: 'App', |
| 21 | + render: () => h(starter), |
| 22 | + components: { starter } |
| 23 | + }) |
| 24 | + |
| 25 | + const wrapper = mount(App) |
| 26 | + // find by DOM selector |
| 27 | + expect(wrapper.findComponent(compA).exists()).toBe(true) |
| 28 | + expect(wrapper.findComponent(compB).exists()).toBe(true) |
| 29 | + expect(wrapper.findComponent(starter).exists()).toBe(true) |
| 30 | + }) |
| 31 | + |
| 32 | + it('finds all components', () => { |
| 33 | + const compC = defineComponent({ |
| 34 | + name: 'compC', |
| 35 | + render: () => h('div', { class: 'B' }, 'TextB') |
| 36 | + }) |
| 37 | + const compB = defineComponent({ |
| 38 | + name: 'compB', |
| 39 | + render: () => h('div', { class: 'B' }, 'TextB') |
| 40 | + }) |
| 41 | + const compA = defineComponent({ |
| 42 | + name: 'compA', |
| 43 | + template: '<div><slot /><slot name="b" /></div>' |
| 44 | + }) |
| 45 | + const starter = defineComponent({ |
| 46 | + name: 'starter', |
| 47 | + template: |
| 48 | + '<comp-a><comp-b /><comp-b /><comp-b /><comp-c v-slot:b /></comp-a>', |
| 49 | + components: { compA, compB, compC } |
| 50 | + }) |
| 51 | + const App = defineComponent({ |
| 52 | + name: 'App', |
| 53 | + template: '<starter />', |
| 54 | + components: { starter } |
| 55 | + }) |
| 56 | + |
| 57 | + const wrapper = mount(App) |
| 58 | + // find by DOM selector |
| 59 | + expect(wrapper.findComponent(compA).exists()).toBe(true) |
| 60 | + expect(wrapper.findComponent(compB).exists()).toBe(true) |
| 61 | + expect(wrapper.findComponent(compC).exists()).toBe(true) |
| 62 | + expect(wrapper.findComponent(starter).exists()).toBe(true) |
| 63 | + }) |
| 64 | +}) |
0 commit comments