Skip to content

Commit 2a25a8b

Browse files
author
willxywang
committed
fix: remove wrapper div when unmount
1 parent 817dd40 commit 2a25a8b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,14 @@ 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, { props: { msg: 'Hello world' }, attachTo: document.body });
110+
expect(document.body.firstChild, 'Container should have mounted component wrapper').toBeInstanceOf(HTMLDivElement);
111+
112+
wrapper.unmount();
113+
expect(document.body.firstChild, 'Container should be empty').toBeNull();
114+
})
105115
})

0 commit comments

Comments
 (0)