Skip to content

container: document.body breaks tests #329

@susnux

Description

@susnux

Describe the bug A clear and concise description of what the bug is.
When having a teleport to body in a component you want to set attachTo of vue test utils to body, to do so you can set container: document.body in testing library.

This causes a problem that now render will remove the body node and causes document.body to be null after calling render.

To Reproduce Steps to reproduce the behavior:

Have a component that teleports to body and then set the container to the body.

Expected behavior
No issues.

Related information:

  • @testing-library/vue version: 8.1.0
  • Vue version: 3.5.25
  • node version: 24
  • npm (or yarn) version: 11

Additional context

This is caused by this line in the render.js:

unwrapNode(wrapper.parentElement);

This fixes it:

if (baseElement !== container) {
  unwrapNode(wrapper.parentElement);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions