Skip to content

Bug: <div> wrapper not cleaned up on unmount #2690

@EwenDC

Description

@EwenDC

Describe the bug

In #219 it was raised that with the Vue 3 upgrade, Vue Test Utils will no longer mount directly to the target provided by the attachTo option, but to a child div element appended to the target. However, the unmount function was never updated to account for this. Both when manually calling unmount, and when using enableAutoUnmount, Vue Test Utils leaves behind the div element it created to mount the component.

This makes it infeasible to use attachTo on the same target in multiple tests, as you end up with a large list of div elements appended to the target from previous tests. Ideally unmount should drop the wrapper element that mount creates so that the mount target is left in a clean state.

Reproduction

https://stackblitz.com/edit/vtu-cleanup-bug?file=src%2Fcomponents%2F__tests__%2FHelloWorld.spec.ts&view=editor

Expected behavior

unmount should not leave an extra div on the element it was attached to.

Environment

System:
OS: macOS 15.5
CPU: (8) arm64 Apple M1 Pro
Memory: 218.30 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
npmPackages:
@vue/test-utils: 2.4.6 => 2.4.6
vitest: 3.2.4 => 3.2.4
vue: 3.5.17 => 3.5.17

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions