Skip to content

Commit 3ecde9e

Browse files
authored
fix: allow unmounting with no wrapper element (#312)
* fix: check wrapper element to fix #311
1 parent f5a3483 commit 3ecde9e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/__tests__/render.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {render} from '..'
1+
import {render, cleanup} from '..'
2+
import {h, defineComponent} from 'vue'
23
import '@testing-library/jest-dom'
34

45
test('baseElement defaults to document.body', () => {
@@ -87,3 +88,15 @@ test('unmounts', () => {
8788

8889
expect(queryByTestId('node')).not.toBeInTheDocument()
8990
})
91+
92+
test('unmounts when no wrapper element is present', () => {
93+
const Comp = defineComponent((_, ctx) => () => ctx.slots.default?.())
94+
95+
const {unmount} = render({
96+
render: () => h(Comp, () => h('div')),
97+
})
98+
99+
unmount()
100+
101+
expect(() => cleanup()).not.toThrow()
102+
})

src/render.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ function cleanup() {
6060
}
6161

6262
function cleanupAtWrapper(wrapper) {
63-
if (
64-
wrapper.element.parentNode &&
65-
wrapper.element.parentNode.parentNode === document.body
66-
) {
63+
if (wrapper.element?.parentNode?.parentNode === document.body) {
6764
document.body.removeChild(wrapper.element.parentNode)
6865
}
6966

0 commit comments

Comments
 (0)