Skip to content

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

Closed

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

Activity

  1. added theissue type on Jul 16, 2025
  2. added
    bug
    on Jul 16, 2025
  3. cexbrayat commented on Jul 16, 2025

    @cexbrayat
    Member

    Hi @EwenDC

    Thanks for the repro. Would you like to try to solve this with a PR? We would be glad to review it and merge it.

  4. added a commit that references this issue on Aug 12, 2025
    4dcea9e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions