diff --git a/src/__tests__/render.js b/src/__tests__/render.js index 151bd8b..ea55817 100644 --- a/src/__tests__/render.js +++ b/src/__tests__/render.js @@ -1,4 +1,5 @@ -import {render} from '..' +import {render, cleanup} from '..' +import {h, defineComponent} from 'vue' import '@testing-library/jest-dom' test('baseElement defaults to document.body', () => { @@ -87,3 +88,15 @@ test('unmounts', () => { expect(queryByTestId('node')).not.toBeInTheDocument() }) + +test('unmounts when no wrapper element is present', () => { + const Comp = defineComponent((_, ctx) => () => ctx.slots.default?.()) + + const {unmount} = render({ + render: () => h(Comp, () => h('div')), + }) + + unmount() + + expect(() => cleanup()).not.toThrow() +}) diff --git a/src/render.js b/src/render.js index 6f635cb..997ba4c 100644 --- a/src/render.js +++ b/src/render.js @@ -60,10 +60,7 @@ function cleanup() { } function cleanupAtWrapper(wrapper) { - if ( - wrapper.element.parentNode && - wrapper.element.parentNode.parentNode === document.body - ) { + if (wrapper.element?.parentNode?.parentNode === document.body) { document.body.removeChild(wrapper.element.parentNode) }