@@ -47,6 +47,7 @@ to maintain.
4747 * [ ` toHaveAttribute ` ] ( #tohaveattribute )
4848 * [ ` toHaveClass ` ] ( #tohaveclass )
4949 * [ ` toHaveStyle ` ] ( #tohavestyle )
50+ * [ ` toBeVisible ` ] ( #tobevisible )
5051* [ Inspiration] ( #inspiration )
5152* [ Other Solutions] ( #other-solutions )
5253* [ Guiding Principles] ( #guiding-principles )
@@ -194,6 +195,35 @@ This also works with rules that are applied to the element via a class name for
194195which some rules are defined in a stylesheet currently active in the document.
195196The usual rules of css precedence apply.
196197
198+ ### ` toBeVisible `
199+
200+ This allows you to check if an element is currently visible to the user.
201+
202+ An element is visible if ** all** the following conditions are met:
203+
204+ * it does not have its css property ` display ` set to ` none `
205+ * it does not have its css property ` visibility ` set to either ` hidden ` or
206+ ` collapse `
207+ * it does not have its css property ` opacity ` set to ` 0 `
208+ * its parent element is also visible (and so on up to the top of the DOM tree)
209+
210+ ``` javascript
211+ // add the custom expect matchers once
212+ import ' jest-dom/extend-expect'
213+
214+ // ...
215+ // <header>
216+ // <h1 style="display: none">Page title</h1>
217+ // </header>
218+ // <section>
219+ // <p style="visibility: hidden">Hello <strong>World</strong></h1>
220+ // </section>
221+ expect (container .querySelector (' header' )).toBeVisible ()
222+ expect (container .querySelector (' h1' )).not .toBeVisible ()
223+ expect (container .querySelector (' strong' )).not .toBeVisible ()
224+ // ...
225+ ```
226+
197227## Inspiration
198228
199229This whole library was extracted out of Kent C. Dodds' [ dom-testing-library] [ ] ,
0 commit comments