`container: document.body` breaks tests
bug
<!-- Thanks for your interest in the project. We appreciate bugs filed and PRs submitted! -->
<!--
- For questions related to using the library, please join the Discord server (https://discord.gg/testing-library) instead of filing an issue on GitHub.
- Please fill out this template with all the relevant information so we can
understand what's going on and fix the issue.
- If you're issue is regarding one of the query APIs (`getByText`,
`getByLabelText`, etc), then please file it on the `@testing-library/dom`
repository instead. Thanks :)
--->
**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:
<!-- Please try to provide a working demo using Codesandbox, a GitHub repo or similar! -->
Have a component that teleports to body and then set the container to the body.
**Expected behavior**
No issues.
<!-- A clear and concise description of what you expected to happen. -->
**Related information:**
- `@testing-library/vue` version: 8.1.0
- `Vue` version: 3.5.25
- `node` version: 24
- `npm` (or `yarn`) version: 11
**Additional context**
<!-- Add any other context about the problem here. -->
This is caused by this line in the `render.js`:
```js
unwrapNode(wrapper.parentElement);
```
This fixes it:
```js
if (baseElement !== container) {
unwrapNode(wrapper.parentElement);
}
```
1 条评论