Open
Description
I was working on something using the <details />
element and was looking to test whether the inner text was visible or not. What I found out while looking through the code/tests for toBeVisible() is that:
- The inner text needs to be inside another element. e.g.
<details>
<summary>Title</summary>
<div>Explanation text</div>
</details>
- This is necessary because of the previousElement check in isAttributeVisible
Line 19 in d24b6be
- When a
<details />
element without enclosed inner text is used in conjunction with React Testing Library, you'll receiveTypeError: Cannot read property 'nodeName' of undefined
. E.g.
<details>
<summary>This will not work</summary>
Unenclosed Inner Text
</details>
expect(getByText('Unenclosed Inner Text')).not.toBeVisible();
- While the documentation does mention that toBeVisible() works with
<details />
elements with the open attribute, it neither mentions the above or give an example.
Since <details />
elements do not need to have an enclosing element for their inner text, see the first example https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details, it should be clearer that this is necessary. It's probably ok if this acts as it is, I just think it should be clearer that it's explicitly necessary and there should probably be an example for <details />
regardless.