17
17
[ ![ downloads] [ downloads-badge ]] [ npmtrends ]
18
18
[ ![ MIT License] [ license-badge ]] [ license ]
19
19
20
- [ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-44 -orange.svg?style=flat-square )] ( #contributors )
20
+ [ ![ All Contributors] ( https://img.shields.io/badge/all_contributors-45 -orange.svg?style=flat-square )] ( #contributors )
21
21
[ ![ PRs Welcome] [ prs-badge ]] [ prs ]
22
22
[ ![ Code of Conduct] [ coc-badge ]] [ coc ]
23
23
@@ -81,11 +81,10 @@ when a real user uses it.
81
81
- [ Usage] ( #usage )
82
82
- [ ` getByLabelText ` ] ( #getbylabeltext )
83
83
- [ ` getByPlaceholderText ` ] ( #getbyplaceholdertext )
84
- - [ ` getBySelectText ` ] ( #getbyselecttext )
85
84
- [ ` getByText ` ] ( #getbytext )
86
85
- [ ` getByAltText ` ] ( #getbyalttext )
87
86
- [ ` getByTitle ` ] ( #getbytitle )
88
- - [ ` getByValue ` ] ( #getbyvalue )
87
+ - [ ` getByDisplayValue ` ] ( #getbydisplayvalue )
89
88
- [ ` getByRole ` ] ( #getbyrole )
90
89
- [ ` getByTestId ` ] ( #getbytestid )
91
90
- [ ` wait ` ] ( #wait )
@@ -276,35 +275,6 @@ const inputNode = getByPlaceholderText(container, 'Username')
276
275
> NOTE: a placeholder is not a good substitute for a label so you should
277
276
> generally use ` getByLabelText ` instead.
278
277
279
- ### ` getBySelectText `
280
-
281
- ``` typescript
282
- getBySelectText (
283
- container : HTMLElement ,
284
- text : TextMatch ,
285
- options ?: {
286
- exact?: boolean = true ,
287
- collapseWhitespace?: boolean = true ,
288
- trim?: boolean = true ,
289
- }): HTMLElement
290
- ```
291
-
292
- This will search for a ` <select> ` whose selected ` <option> ` matches the given [ ` TextMatch ` ] ( #textmatch ) . This would find the ` <select> ` node in a situation
293
- where the first value acts as a sort of placeholder for the dropdown.
294
-
295
- ``` javascript
296
- // <select>
297
- // <option value="">Day of the Week</option>
298
- // <option value="1">Monday</option>
299
- // <option value="2">Tuesday</option>
300
- // <option value="3">Wednesday</option>
301
- // </select>
302
- const selectNode = getBySelectText (container, ' Day of the Week' )
303
- ```
304
-
305
- > Note: It is highly preferred to use ` getByLabelText ` over this method. This
306
- > method should only be used in the event where there is no label text available.
307
-
308
278
### ` getByText `
309
279
310
280
``` typescript
@@ -390,10 +360,10 @@ Will also find a `title` element within an SVG.
390
360
const closeElement = getByTitle (container, ' Close' )
391
361
```
392
362
393
- ### ` getByValue `
363
+ ### ` getByDisplayValue `
394
364
395
365
``` typescript
396
- getByValue (
366
+ getByDisplayValue (
397
367
container : HTMLElement ,
398
368
value : TextMatch ,
399
369
options ?: {
@@ -403,13 +373,41 @@ getByValue(
403
373
}): HTMLElement
404
374
```
405
375
406
- Returns the element that has the matching value.
376
+ Returns the ` input ` , ` textarea ` , or ` select ` element that has the matching display value.
377
+
378
+ #### ` input `
379
+
380
+ ``` javascript
381
+ // <input type="text" id="lastName" />
382
+ // document.getElementById('lastName').value = 'Norris'
383
+
384
+ const lastNameInput = getByDisplayValue (container, ' Norris' )
385
+ ```
386
+
387
+ #### ` textarea `
407
388
408
389
``` javascript
409
- // <input type="text" id="lastName" defaultValue="Norris" />
410
- const lastNameInput = getByValue (' Norris' )
390
+ // <textarea id="messageTextArea"></textarea>
391
+ // document.getElementById('messageTextArea').value = 'Hello World'
392
+
393
+ const messageTextArea = getByDisplayValue (container, ' Hello World' )
411
394
```
412
395
396
+ #### ` select `
397
+
398
+ ``` javascript
399
+ // <select id="state-select" data-testid="state">
400
+ // <option value="">State</option>
401
+ // <option value="AL">Alabama</option>
402
+ // <option selected value="AK" >Alaska</option>
403
+ // <option value="AZ">Arizona</option>
404
+ // </select>
405
+
406
+ const selectElement = getByDisplayName (container, ' Alaska' )
407
+ ```
408
+
409
+ In case of ` select ` , this will search for a ` <select> ` whose selected ` <option> ` matches the given [ ` TextMatch ` ] ( #textmatch ) .
410
+
413
411
### ` getByRole `
414
412
415
413
``` typescript
@@ -1147,7 +1145,7 @@ Thanks goes to these people ([emoji key][emojis]):
1147
1145
| [<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") | [<img src="https://avatars2.githubusercontent.com/u/4126644?v=4" width="100px;"/><br /><sub><b>Sanghyeon Lee</b></sub>](https://github.com/yongdamsh)<br />[💡](#example-yongdamsh "Examples") | [<img src="https://avatars3.githubusercontent.com/u/8015514?v=4" width="100px;"/><br /><sub><b>Justice Mba </b></sub>](https://github.com/Dajust)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Documentation") [🤔](#ideas-Dajust "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/340761?v=4" width="100px;"/><br /><sub><b>Wayne Crouch</b></sub>](https://github.com/wgcrouch)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=wgcrouch "Code") | [<img src="https://avatars1.githubusercontent.com/u/4996462?v=4" width="100px;"/><br /><sub><b>Ben Elliott</b></sub>](http://benjaminelliott.co.uk)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=benelliott "Code") | [<img src="https://avatars3.githubusercontent.com/u/577921?v=4" width="100px;"/><br /><sub><b>Ruben Costa</b></sub>](http://nuances.co)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=rubencosta "Code") | [<img src="https://avatars2.githubusercontent.com/u/4982001?v=4" width="100px;"/><br /><sub><b>Robert Smith</b></sub>](http://rbrtsmith.com/)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Arbrtsmith "Bug reports") [🤔](#ideas-rbrtsmith "Ideas, Planning, & Feedback") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=rbrtsmith "Documentation") |
1148
1146
| [<img src="https://avatars3.githubusercontent.com/u/881986?v=4" width="100px;"/><br /><sub><b>dadamssg</b></sub>](https://github.com/dadamssg)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dadamssg "Code") | [<img src="https://avatars1.githubusercontent.com/u/186971?v=4" width="100px;"/><br /><sub><b>Neil Kistner</b></sub>](https://neilkistner.com/)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=wyze "Code") | [<img src="https://avatars3.githubusercontent.com/u/1448597?v=4" width="100px;"/><br /><sub><b>Ben Chauvette</b></sub>](http://bdchauvette.net/)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=bdchauvette "Code") | [<img src="https://avatars2.githubusercontent.com/u/777527?v=4" width="100px;"/><br /><sub><b>Jeff Baumgardt</b></sub>](https://github.com/JeffBaumgardt)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/4658208?v=4" width="100px;"/><br /><sub><b>Matan Kushner</b></sub>](http://matchai.me)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Documentation") [🤔](#ideas-matchai "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Tests") | [<img src="https://avatars2.githubusercontent.com/u/5779538?v=4" width="100px;"/><br /><sub><b>Alex Wendte</b></sub>](http://www.wendtedesigns.com/)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Tests") | [<img src="https://avatars0.githubusercontent.com/u/2196208?v=4" width="100px;"/><br /><sub><b>Tamas Fodor</b></sub>](https://github.com/ruffle1986)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=ruffle1986 "Documentation") |
1149
1147
| [<img src="https://avatars3.githubusercontent.com/u/14793495?v=4" width="100px;"/><br /><sub><b>Benjamin Eckardt</b></sub>](https://github.com/BenjaminEckardt)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=BenjaminEckardt "Code") | [<img src="https://avatars3.githubusercontent.com/u/205752?v=4" width="100px;"/><br /><sub><b>Ryan Campbell</b></sub>](https://github.com/campbellr)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=campbellr "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1335519?v=4" width="100px;"/><br /><sub><b>Taylor Briggs</b></sub>](https://taylor-briggs.com)<br />[⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=TaylorBriggs "Tests") | [<img src="https://avatars2.githubusercontent.com/u/132233?v=4" width="100px;"/><br /><sub><b>John Gozde</b></sub>](https://github.com/jgoz)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jgoz "Code") | [<img src="https://avatars2.githubusercontent.com/u/3382565?v=4" width="100px;"/><br /><sub><b>C. T. Lin</b></sub>](https://github.com/chentsulin)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=chentsulin "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/5312329?v=4" width="100px;"/><br /><sub><b>Terrence Wong</b></sub>](http://terrencewwong.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=terrencewwong "Code") | [<img src="https://avatars0.githubusercontent.com/u/12230408?v=4" width="100px;"/><br /><sub><b>Soo Jae Hwang</b></sub>](https://www.ossfinder.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=misoguy "Code") |
1150
- | [<img src = " https://avatars0.githubusercontent.com/u/19773?v=4" width = " 100px;" / ><br / > <sub ><b >Royston Shufflebotham < / b > </sub >](https :// github.com/RoystonS)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3ARoystonS "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Tests") | [<img src="https://avatars0.githubusercontent.com/u/591673?v=4" width="100px;"/><br /><sub><b>Vadim Brodsky</b></sub>](http://www.vadimbrodsky.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=VadimBrodsky "Code") |
1148
+ | [<img src="https://avatars0.githubusercontent.com/u/19773?v=4" width="100px;"/><br /><sub><b>Royston Shufflebotham</b></sub>](https://github.com/RoystonS)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3ARoystonS "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Tests") | [<img src="https://avatars0.githubusercontent.com/u/591673?v=4" width="100px;"/><br /><sub><b>Vadim Brodsky</b></sub>](http://www.vadimbrodsky.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=VadimBrodsky "Code") | [<img src="https://avatars3.githubusercontent.com/u/499898?v=4" width="100px;"/><br /><sub><b>Eunjae Lee</b></sub>](https://twitter.com/eunjae_lee)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=eunjae-lee "Code") |
1151
1149
1152
1150
<!-- ALL -CONTRIBUTORS -LIST :END -->
1153
1151
0 commit comments