File tree Expand file tree Collapse file tree 3 files changed +91
-1
lines changed Expand file tree Collapse file tree 3 files changed +91
-1
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,12 @@ export class VueWrapper<T extends ComponentPublicInstance> {
79
79
}
80
80
81
81
html ( ) {
82
- return this . parentElement . innerHTML
82
+ // cover cases like <Suspense>, multiple root nodes.
83
+ if ( this . parentElement [ '__vue_app__' ] ) {
84
+ return this . parentElement . innerHTML
85
+ }
86
+
87
+ return this . element . outerHTML
83
88
}
84
89
85
90
text ( ) {
Original file line number Diff line number Diff line change @@ -170,4 +170,60 @@ describe('findComponent', () => {
170
170
const wrapper = mount ( compA )
171
171
expect ( wrapper . findComponent ( Hello ) . unmount ) . toThrowError ( )
172
172
} )
173
+
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' , ( ) => {
186
+ const wrapper = mount ( {
187
+ components : {
188
+ ComponentA,
189
+ ComponentB
190
+ } ,
191
+ template : `
192
+ <ComponentA>
193
+ <ComponentB>1</ComponentB>
194
+ <ComponentB>2</ComponentB>
195
+ <ComponentB>3</ComponentB>
196
+ </ComponentA>
197
+ `
198
+ } )
199
+ const com1 = wrapper . findComponent ( ComponentB )
200
+ expect ( com1 . html ( ) ) . toBe ( '<div>1</div>' )
201
+ } )
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
+ } )
173
229
} )
Original file line number Diff line number Diff line change @@ -50,4 +50,33 @@ describe('html', () => {
50
50
const wrapper = mount ( Component )
51
51
expect ( wrapper . html ( ) ) . toEqual ( '<div class="Foo">FOO</div>' )
52
52
} )
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
+ } )
53
82
} )
You can’t perform that action at this time.
0 commit comments