testing-library / testing-library/react-testing-library
When `container` is `document`, cleanup steps fails with "TypeError: Cannot read properties of null (reading 'removeChild')"
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 19.7k
- Forks
- 1.2k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
Just opening this for tracking with the associated PR: #1330 .
When:
render(<Component />, { container: document });
(Untested: This bug may require that Component render a <body> element.)
Then:
TypeError: Cannot read properties of null (reading 'removeChild')
Because:
// pure.js
if (container.parentNode === document.body) {
document.body.removeChild(container);
}
If we first check that document.body is not null, then this error will not occur.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pure.js at the cleanup condition that calls document.body.removeChild(container). Reproduce render(, { container: document }) and verify cleanup when document.body is null; done means the TypeError no longer occurs. The issue mentions associated PR #1330, so check its status before starting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100