Skip to content

Commit 4dcea9e

Browse files
fix: remove wrapper div when unmount (#2700)
Fixes #2690
1 parent 817dd40 commit 4dcea9e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/mount.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export function mount(
9999
}
100100

101101
to.appendChild(el)
102+
app.onUnmount(() => {
103+
to?.removeChild(el)
104+
})
102105
}
103106
const vm = app.mount(el)
104107
if (errorsOnMount.length) {

tests/mount.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,20 @@ describe('mount: general tests', () => {
102102
})
103103
expect(wrapper.text()).toContain('Hello world')
104104
})
105+
106+
it('should remove wrapper div when unmount', () => {
107+
expect(document.body.firstChild, 'Container should be empty').toBeNull()
108+
109+
const wrapper = mount(Hello, {
110+
props: { msg: 'Hello world' },
111+
attachTo: document.body
112+
})
113+
expect(
114+
document.body.firstChild,
115+
'Container should have mounted component wrapper'
116+
).toBeInstanceOf(HTMLDivElement)
117+
118+
wrapper.unmount()
119+
expect(document.body.firstChild, 'Container should be empty').toBeNull()
120+
})
105121
})

0 commit comments

Comments
 (0)