Skip to content

Commit ccb460b

Browse files
refactor: make hasMultipleRoots a private property
1 parent 6d6e7ae commit ccb460b

File tree

3 files changed

+27
-36
lines changed

3 files changed

+27
-36
lines changed

src/vue-wrapper.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export class VueWrapper implements WrapperAPI {
1818
this.__emitted = events
1919
}
2020

21-
get __hasMultipleRoots(): boolean {
21+
private get hasMultipleRoots(): boolean {
2222
// if the subtree is an array of children, we have multiple root nodes
2323
return this.componentVM.$.subTree.shapeFlag === ShapeFlags.ARRAY_CHILDREN
2424
}
2525

2626
get element() {
27-
return this.__hasMultipleRoots
27+
return this.hasMultipleRoots
2828
? // get the parent element of the current component
2929
this.componentVM.$el.parentElement
3030
: this.componentVM.$el
@@ -47,7 +47,9 @@ export class VueWrapper implements WrapperAPI {
4747
}
4848

4949
html() {
50-
return this.element.outerHTML
50+
return this.hasMultipleRoots
51+
? this.element.innerHTML
52+
: this.element.outerHTML
5153
}
5254

5355
text() {

tests/html-text.spec.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@ import { defineComponent, h } from 'vue'
22

33
import { mount } from '../src'
44

5-
test('html, text', () => {
6-
const Component = defineComponent({
7-
render() {
8-
return h('div', {}, 'Text content')
9-
}
5+
describe('html', () => {
6+
it('returns html when mounting single root node', () => {
7+
const Component = defineComponent({
8+
render() {
9+
return h('div', {}, 'Text content')
10+
}
11+
})
12+
13+
const wrapper = mount(Component)
14+
15+
expect(wrapper.html()).toBe('<div>Text content</div>')
1016
})
1117

12-
const wrapper = mount(Component)
18+
it('returns the html when mounting multiple root nodes', () => {
19+
const Component = defineComponent({
20+
render() {
21+
return [h('div', {}, 'foo'), h('div', {}, 'bar'), h('div', {}, 'baz')]
22+
}
23+
})
1324

14-
expect(wrapper.html()).toBe('<div>Text content</div>')
15-
expect(wrapper.text()).toBe('Text content')
16-
})
25+
const wrapper = mount(Component)
26+
27+
expect(wrapper.html()).toBe('<div>foo</div><div>bar</div><div>baz</div>')
28+
})
29+
})

tests/multipleRootNodes.spec.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)