@@ -351,10 +351,10 @@ Returns the element that has the matching value.
351
351
const lastNameInput = getByValue (' Norris' )
352
352
```
353
353
354
- ### ` getByTestId `
354
+ ### ` getByRole `
355
355
356
356
``` typescript
357
- getByTestId (
357
+ getByRole (
358
358
container : HTMLElement ,
359
359
text : TextMatch ,
360
360
options ?: {
@@ -364,26 +364,18 @@ getByTestId(
364
364
}): HTMLElement `
365
365
` ` `
366
366
367
- A shortcut to ` ` container .querySelector (` [data-testid ="${yourId }"] ` ) ` ` (and it
367
+ A shortcut to ` ` container .querySelector (` [role ="${yourRole }"] ` ) ` ` (and it
368
368
also accepts a [` TextMatch ` ](#textmatch )).
369
369
370
370
` ` ` javascript
371
- // <input data-testid="username-input" / >
372
- const usernameInputElement = getByTestId (container, 'username-input ')
371
+ // <div role="dialog">...</div >
372
+ const dialogContainer = getByTestrole (container, 'dialog ')
373
373
` ` `
374
374
375
- > In the spirit of [the guiding principles ](#guiding - principles ), it is
376
- > recommended to use this only after the other queries don ' t work for your use
377
- > case . Using data - testid attributes do not resemble how your software is used
378
- > and should be avoided if possible . That said , they are _way_ better than
379
- > querying based on DOM structure or styling css class names . Learn more about
380
- > `data -testid `s from the blog post
381
- > ["Making your UI tests resilient to change "][data -testid -blog -post ]
382
-
383
- ### `getByRole `
375
+ ### ` getByTestId `
384
376
385
377
` ` ` typescript
386
- getByRole (
378
+ getByTestId (
387
379
container: HTMLElement,
388
380
text: TextMatch,
389
381
options?: {
@@ -393,14 +385,22 @@ getByRole(
393
385
}): HTMLElement `
394
386
```
395
387
396
- A shortcut to ` ` container .querySelector (` [role ="${yourRole }"] ` ) ` ` (and it
388
+ A shortcut to `` container.querySelector(`[data-testid ="${yourId }"]`) `` (and it
397
389
also accepts a [ ` TextMatch ` ] ( #textmatch ) ).
398
390
399
391
``` javascript
400
- // <div role="dialog">...</div >
401
- const dialogContainer = getByTestrole (container, 'dialog ')
392
+ // <input data-testid="username-input" / >
393
+ const usernameInputElement = getByTestId (container, ' username-input ' )
402
394
```
403
395
396
+ > In the spirit of [ the guiding principles] ( #guiding-principles ) , it is
397
+ > recommended to use this only after the other queries don't work for your use
398
+ > case. Using data-testid attributes do not resemble how your software is used
399
+ > and should be avoided if possible. That said, they are _ way_ better than
400
+ > querying based on DOM structure or styling css class names. Learn more about
401
+ > ` data-testid ` s from the blog post
402
+ > [ "Making your UI tests resilient to change"] [ data-testid-blog-post ]
403
+
404
404
### ` wait `
405
405
406
406
``` typescript
@@ -955,6 +955,7 @@ Thanks goes to these people ([emoji key][emojis]):
955
955
| [<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") |
956
956
| [<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") |
957
957
| [<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") |
958
+
958
959
<!-- ALL -CONTRIBUTORS -LIST :END -->
959
960
960
961
This project follows the [all -contributors ][all -contributors ] specification .
0 commit comments