diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index bf0f8fcc9..283a36a7e 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -216,10 +216,7 @@ export class VueWrapper { ) } - if (this.parentElement) { - this.parentElement.removeChild(this.element) - } - this.__app.unmount(this.element) + this.__app.unmount(this.parentElement) } } diff --git a/tests/unmount.spec.ts b/tests/unmount.spec.ts new file mode 100644 index 000000000..f9f824763 --- /dev/null +++ b/tests/unmount.spec.ts @@ -0,0 +1,44 @@ +import { defineComponent } from 'vue' + +import { mount } from '../src' + +describe('Unmount', () => { + it('works on single root component', () => { + const errorHandler = jest.fn() + const Component = { + template: ` +
+ ` + } + const wrapper = mount(Component, { + props: {}, + global: { + config: { + errorHandler + } + } + } as any) // The type checking keeps complaning about unmatched type which might be a bug + wrapper.unmount() + expect(errorHandler).not.toHaveBeenCalled() + }) + + it('works on multi-root component', () => { + const errorHandler = jest.fn() + const Component = defineComponent({ + template: ` +
+
+ ` + }) + const wrapper = mount(Component, { + props: {}, + global: { + config: { + errorHandler + } + } + } as any) + wrapper.unmount() + expect(errorHandler).not.toHaveBeenCalled() + }) +})