As reported by @sompylasar in testing-library/dom-testing-library#9 .toBeInTheDOM
is not really checking for what it name implies (because it does not have the concept of what "the DOM" is to being with). Right now is just a glorified .toBeInstanceOfClass(HTMLElement)
.
Refer to the original discussion for all suggested solutions. I'll mention here a few from there plus a new one:
// I kinda favor something like this (exact name is open for discussion) expect(container).toContainElement(element) // This makes me wonder if it only checks for direct parent-child relationship // We could add it too, but not as a solution to this issue expect(element).toBeAChildOf(parent) // Keep .toBeInTheDOM allowing it to receive an optional element // This still does not solve the problem when the container is not given, but I wouldn't rule it out expect(element).toBeInTheDOM() expect(element).toBeInTheDOM(container)
sompylasar and kentcdodds
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4