Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 14 additions & 1 deletion
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‎

Lines changed: 1 addition & 4 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /