Skip to content

Commit 199239f

Browse files
committed
bugfix/unmounting-on-multi-root
- Fix the logic which causes unmounting fail when it's multi-root component
1 parent e5aee88 commit 199239f

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/vueWrapper.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ export class VueWrapper<T extends ComponentPublicInstance> {
216216
)
217217
}
218218

219-
if (this.parentElement) {
220-
this.parentElement.removeChild(this.element)
221-
}
222-
this.__app.unmount(this.element)
219+
this.__app.unmount(this.parentElement)
223220
}
224221
}
225222

tests/unmount.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { mount } from '../src'
2+
3+
const AXIOM = 'Rem is the best girl'
4+
5+
describe('Unmount', () => {
6+
it('works on single root component', () => {
7+
const Component = {
8+
template: `
9+
<div>${AXIOM}</div>
10+
`,
11+
onErrorCaptured(err: Error) {
12+
throw err
13+
}
14+
}
15+
const wrapper = mount(Component)
16+
expect(() => wrapper.unmount()).not.toThrowError()
17+
})
18+
19+
it('works on multi-root component', () => {
20+
const Component = {
21+
template: `
22+
<div>${AXIOM}</div>
23+
<div>${AXIOM}</div>
24+
`,
25+
onErrorCaptured(err: Error) {
26+
throw err
27+
}
28+
}
29+
const wrapper = mount(Component)
30+
wrapper.unmount()
31+
})
32+
})

0 commit comments

Comments
 (0)