16
16
[ ![ downloads] [ downloads-badge ]] [ npmtrends ]
17
17
[ ![ MIT License] [ license-badge ]] [ license ]
18
18
19
- [ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-21 -orange.svg?style=flat-square )] ( #contributors )
19
+ [ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-22 -orange.svg?style=flat-square )] ( #contributors )
20
20
[ ![ PRs Welcome] [ prs-badge ]] [ prs ]
21
21
[ ![ Code of Conduct] [ coc-badge ]] [ coc ]
22
22
@@ -67,37 +67,36 @@ when a real user uses it.
67
67
## Table of Contents
68
68
69
69
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
70
-
71
70
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
72
71
73
- * [ Installation] ( #installation )
74
- * [ Usage] ( #usage )
75
- * [ ` getByLabelText ` ] ( #getbylabeltext )
76
- * [ ` getByPlaceholderText ` ] ( #getbyplaceholdertext )
77
- * [ ` getByText ` ] ( #getbytext )
78
- * [ ` getByAltText ` ] ( #getbyalttext )
79
- * [ ` getByTitle ` ] ( #getbytitle )
80
- * [ ` getByValue ` ] ( #getbyvalue )
81
- * [ ` getByTestId ` ] ( #getbytestid )
82
- * [ ` wait ` ] ( #wait )
83
- * [ ` waitForElement ` ] ( #waitforelement )
84
- * [ ` fireEvent ` ] ( #fireevent )
85
- * [ Custom Jest Matchers] ( #custom-jest-matchers )
86
- * [ Using other assertion libraries] ( #using-other-assertion-libraries )
87
- * [ ` TextMatch ` ] ( #textmatch )
88
- * [ Precision] ( #precision )
89
- * [ TextMatch Examples] ( #textmatch-examples )
90
- * [ ` query ` APIs] ( #query-apis )
91
- * [ ` queryAll ` and ` getAll ` APIs] ( #queryall-and-getall-apis )
92
- * [ ` getQueriesForElement ` ] ( #getqueriesforelement )
93
- * [ Debugging] ( #debugging )
94
- * [ ` prettyDOM ` ] ( #prettydom )
95
- * [ Implementations] ( #implementations )
96
- * [ FAQ] ( #faq )
97
- * [ Other Solutions] ( #other-solutions )
98
- * [ Guiding Principles] ( #guiding-principles )
99
- * [ Contributors] ( #contributors )
100
- * [ LICENSE] ( #license )
72
+ - [ Installation] ( #installation )
73
+ - [ Usage] ( #usage )
74
+ - [ ` getByLabelText ` ] ( #getbylabeltext )
75
+ - [ ` getByPlaceholderText ` ] ( #getbyplaceholdertext )
76
+ - [ ` getByText ` ] ( #getbytext )
77
+ - [ ` getByAltText ` ] ( #getbyalttext )
78
+ - [ ` getByTitle ` ] ( #getbytitle )
79
+ - [ ` getByValue ` ] ( #getbyvalue )
80
+ - [ ` getByTestId ` ] ( #getbytestid )
81
+ - [ ` wait ` ] ( #wait )
82
+ - [ ` waitForElement ` ] ( #waitforelement )
83
+ - [ ` fireEvent ` ] ( #fireevent )
84
+ - [ Custom Jest Matchers] ( #custom-jest-matchers )
85
+ - [ Using other assertion libraries] ( #using-other-assertion-libraries )
86
+ - [ ` TextMatch ` ] ( #textmatch )
87
+ - [ Precision] ( #precision )
88
+ - [ TextMatch Examples] ( #textmatch-examples )
89
+ - [ ` query ` APIs] ( #query-apis )
90
+ - [ ` queryAll ` and ` getAll ` APIs] ( #queryall-and-getall-apis )
91
+ - [ ` getQueriesForElement ` ] ( #getqueriesforelement )
92
+ - [ Debugging] ( #debugging )
93
+ - [ ` prettyDOM ` ] ( #prettydom )
94
+ - [ Implementations] ( #implementations )
95
+ - [ FAQ] ( #faq )
96
+ - [ Other Solutions] ( #other-solutions )
97
+ - [ Guiding Principles] ( #guiding-principles )
98
+ - [ Contributors] ( #contributors )
99
+ - [ LICENSE] ( #license )
101
100
102
101
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
103
102
@@ -114,8 +113,8 @@ npm install --save-dev dom-testing-library
114
113
115
114
Note:
116
115
117
- * Each of the ` get ` APIs below have a matching [ ` getAll ` ] ( #queryall-and-getall-apis ) API that returns all elements instead of just the first one, and [ ` query ` ] ( #query-apis ) /[ ` getAll ` ] ( #queryall-and-getall-apis ) that return ` null ` /` [] ` instead of throwing an error.
118
- * See [ TextMatch] ( #textmatch ) for details on the ` exact ` , ` trim ` , and ` collapseWhitespace ` options.
116
+ - Each of the ` get ` APIs below have a matching [ ` getAll ` ] ( #queryall-and-getall-apis ) API that returns all elements instead of just the first one, and [ ` query ` ] ( #query-apis ) /[ ` getAll ` ] ( #queryall-and-getall-apis ) that return ` null ` /` [] ` instead of throwing an error.
117
+ - See [ TextMatch] ( #textmatch ) for details on the ` exact ` , ` trim ` , and ` collapseWhitespace ` options.
119
118
120
119
``` javascript
121
120
// src/__tests__/example.js
@@ -262,6 +261,7 @@ getByText(
262
261
container : HTMLElement ,
263
262
text : TextMatch ,
264
263
options ?: {
264
+ selector?: string = ' *' ,
265
265
exact?: boolean = true ,
266
266
collapseWhitespace?: boolean = true ,
267
267
trim?: boolean = true ,
@@ -276,6 +276,8 @@ matching the given [`TextMatch`](#textmatch).
276
276
const aboutAnchorNode = getByText (container, ' about' )
277
277
```
278
278
279
+ > NOTE: see [ ` getbylabeltext ` ] ( #getbylabeltext ) for more details on how and when to use the ` selector ` option
280
+
279
281
### ` getByAltText `
280
282
281
283
``` typescript
@@ -559,7 +561,7 @@ If you're not using jest, you may be able to find a similar set of custom
559
561
assertions for your library of choice . Here ' s a list of alternatives to jest-dom
560
562
for other popular assertion libraries :
561
563
562
- * [chai -dom ](https :// github.com/nathanboktae/chai-dom)
564
+ - [chai -dom ](https :// github.com/nathanboktae/chai-dom)
563
565
564
566
If you ' re aware of some other alternatives, please [make a pull request][prs]
565
567
and add it here !
@@ -574,13 +576,13 @@ Several APIs accept a `TextMatch` which can be a `string`, `regex` or a
574
576
Some APIs accept an object as the final argument that can contain options that
575
577
affect the precision of string matching :
576
578
577
- * ` exact ` : Defaults to ` true ` ; matches full strings , case -sensitive . When false ,
579
+ - ` exact ` : Defaults to ` true ` ; matches full strings , case -sensitive . When false ,
578
580
matches substrings and is not case -sensitive .
579
- * ` exact ` has no effect on ` regex ` or ` function ` arguments .
580
- * In most cases using a regex instead of a string gives you more control over
581
+ - ` exact ` has no effect on ` regex ` or ` function ` arguments .
582
+ - In most cases using a regex instead of a string gives you more control over
581
583
fuzzy matching and should be preferred over ` { exact: false } ` .
582
- * ` trim ` : Defaults to ` true ` ; trim leading and trailing whitespace .
583
- * ` collapseWhitespace ` : Defaults to ` true ` . Collapses inner whitespace (newlines , tabs , repeated spaces ) into a single space .
584
+ - ` trim ` : Defaults to ` true ` ; trim leading and trailing whitespace .
585
+ - ` collapseWhitespace ` : Defaults to ` true ` . Collapses inner whitespace (newlines , tabs , repeated spaces ) into a single space .
584
586
585
587
### TextMatch Examples
586
588
@@ -717,7 +719,7 @@ of these utilities was in the `react-testing-library`.
717
719
718
720
Implementations include :
719
721
720
- * [` react-testing-library ` ](https :// github.com/kentcdodds/react-testing-library)
722
+ - [` react-testing-library ` ](https :// github.com/kentcdodds/react-testing-library)
721
723
722
724
## FAQ
723
725
@@ -862,6 +864,8 @@ Thanks goes to these people ([emoji key][emojis]):
862
864
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
863
865
| [<img src="https://avatars1.githubusercontent.com/u/1241511?s=460&v=4" width="100px;"/><br /><sub><b>Anto Aravinth</b></sub>](https://github.com/antoaravinth)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Tests") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3462296?v=4" width="100px;"/><br /><sub><b>Jonah Moses</b></sub>](https://github.com/JonahMoses)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JonahMoses "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Tests") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Asompylasar "Bug reports") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/4439618?v=4" width="100px;"/><br /><sub><b>Jesse Day</b></sub>](https://github.com/jday3)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jday3 "Code") | [<img src="https://avatars0.githubusercontent.com/u/15199?v=4" width="100px;"/><br /><sub><b>Ernesto García</b></sub>](http://gnapse.github.io)<br />[💬](#question-gnapse "Answering Questions") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/2747424?v=4" width="100px;"/><br /><sub><b>Josef Maxx Blake</b></sub>](http://jomaxx.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Tests") |
864
866
| [<img src="https://avatars3.githubusercontent.com/u/725236?v=4" width="100px;"/><br /><sub><b>Alex Cook</b></sub>](https://github.com/alecook)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=alecook "Documentation") [💡](#example-alecook "Examples") | [<img src="https://avatars3.githubusercontent.com/u/10348212?v=4" width="100px;"/><br /><sub><b>Daniel Cook</b></sub>](https://github.com/dfcook)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Tests") | [<img src="https://avatars2.githubusercontent.com/u/21194045?s=400&v=4" width="100px;"/><br /><sub><b>Thomas Chia</b></sub>](https://github.com/thchia)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Athchia "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=thchia "Code") | [<img src="https://avatars1.githubusercontent.com/u/28659384?v=4" width="100px;"/><br /><sub><b>Tim Deschryver</b></sub>](https://github.com/tdeschryver)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Tests") | [<img src="https://avatars3.githubusercontent.com/u/1571667?v=4" width="100px;"/><br /><sub><b>Alex Krolick</b></sub>](https://alexkrolick.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=alexkrolick "Code") | [<img src="https://avatars2.githubusercontent.com/u/2224291?v=4" width="100px;"/><br /><sub><b>Maddi Joyce</b></sub>](http://www.maddijoyce.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=maddijoyce "Code") | [<img src="https://avatars1.githubusercontent.com/u/25429764?v=4" width="100px;"/><br /><sub><b>Peter Kamps</b></sub>](https://github.com/npeterkamps)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Anpeterkamps "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=npeterkamps "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=npeterkamps "Tests") |
867
+ | [<img src = " https://avatars2.githubusercontent.com/u/21689428?v=4" width = " 100px;" / ><br / > <sub ><b >Jonathan Stoye < / b > </sub >](http :// jonathanstoye.de)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JonathanStoye "Documentation") |
868
+
865
869
<!-- ALL -CONTRIBUTORS -LIST :END -->
866
870
867
871
This project follows the [all -contributors ][all -contributors ] specification .
0 commit comments