Skip to content

Commit fc045f7

Browse files
committed
tests: add more tests
1 parent 6a6dd41 commit fc045f7

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

tests/findComponent.spec.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,18 @@ describe('findComponent', () => {
171171
expect(wrapper.findComponent(Hello).unmount).toThrowError()
172172
})
173173

174-
it('finds nested componens', () => {
175-
// https://github.com/vuejs/vue-test-utils-next/issues/173
176-
const ComponentA = {
177-
name: 'ComponentA',
178-
template: `<div><slot></slot></div>`
179-
}
180-
181-
const ComponentB = {
182-
name: 'ComponentB',
183-
template: '<div><slot></slot></div>'
184-
}
174+
// https://github.com/vuejs/vue-test-utils-next/issues/173
175+
const ComponentA = {
176+
name: 'ComponentA',
177+
template: `<div><slot></slot></div>`
178+
}
179+
180+
const ComponentB = {
181+
name: 'ComponentB',
182+
template: '<div><slot></slot></div>'
183+
}
184+
185+
it('finds nested components and obtains expected html and innerText', () => {
185186
const wrapper = mount({
186187
components: {
187188
ComponentA,
@@ -198,4 +199,31 @@ describe('findComponent', () => {
198199
const com1 = wrapper.findComponent(ComponentB)
199200
expect(com1.html()).toBe('<div>1</div>')
200201
})
202+
203+
it('finds nested components and obtains expected html and innerText', () => {
204+
const wrapper = mount({
205+
components: {
206+
ComponentA,
207+
ComponentB
208+
},
209+
template: `
210+
<ComponentA>
211+
<ComponentB>
212+
<div class="content" id="1">1</div>
213+
</ComponentB>
214+
<ComponentB>
215+
<div class="content" id="2">2</div>
216+
</ComponentB>
217+
<ComponentB>
218+
<div class="content" id="3">3</div>
219+
</ComponentB>
220+
</ComponentA>
221+
`
222+
})
223+
224+
const compB = wrapper.findAllComponents(ComponentB)
225+
expect(compB[0].find('.content').text()).toBe('1')
226+
expect(compB[0].vm.$el.querySelector('.content').innerHTML).toBe('1')
227+
expect(compB[0].vm.$el.querySelector('.content').textContent).toBe('1')
228+
})
201229
})

tests/html.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,33 @@ describe('html', () => {
5050
const wrapper = mount(Component)
5151
expect(wrapper.html()).toEqual('<div class="Foo">FOO</div>')
5252
})
53+
54+
it('returns the html with findComponent in a nested Suspense component', () => {
55+
const Foo = defineComponent({
56+
template: '<div class="Foo">FOO</div>',
57+
setup() {
58+
return {}
59+
}
60+
})
61+
const Component = {
62+
template: `
63+
<div>
64+
<span>
65+
<Suspense>
66+
<template #default>
67+
<Foo />
68+
</template>
69+
70+
<template #fallback>
71+
Fallback
72+
</template>
73+
</Suspense>
74+
</span>
75+
</div>`,
76+
components: { Foo }
77+
}
78+
const wrapper = mount(Component)
79+
const foo = wrapper.findComponent(Foo)
80+
expect(foo.html()).toEqual('<div class="Foo">FOO</div>')
81+
})
5382
})

0 commit comments

Comments
 (0)