Skip to content

Commit e3daca6

Browse files
authored
Merge pull request #182 from JeremyWuuuuu/bugfix/unmounting-on-multi-root
bugfix/unmounting-on-multi-root
2 parents e5aee88 + 15fdd87 commit e3daca6

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { defineComponent } from 'vue'
2+
3+
import { mount } from '../src'
4+
5+
describe('Unmount', () => {
6+
it('works on single root component', () => {
7+
const errorHandler = jest.fn()
8+
const Component = {
9+
template: `
10+
<div></div>
11+
`
12+
}
13+
const wrapper = mount(Component, {
14+
props: {},
15+
global: {
16+
config: {
17+
errorHandler
18+
}
19+
}
20+
} as any) // The type checking keeps complaning about unmatched type which might be a bug
21+
wrapper.unmount()
22+
expect(errorHandler).not.toHaveBeenCalled()
23+
})
24+
25+
it('works on multi-root component', () => {
26+
const errorHandler = jest.fn()
27+
const Component = defineComponent({
28+
template: `
29+
<div></div>
30+
<div></div>
31+
`
32+
})
33+
const wrapper = mount(Component, {
34+
props: {},
35+
global: {
36+
config: {
37+
errorHandler
38+
}
39+
}
40+
} as any)
41+
wrapper.unmount()
42+
expect(errorHandler).not.toHaveBeenCalled()
43+
})
44+
})

0 commit comments

Comments
 (0)