|
10 | 10 |
|
11 | 11 | <hr />
|
12 | 12 |
|
| 13 | +<!-- prettier-ignore-start --> |
13 | 14 | [![Build Status][build-badge]][build]
|
14 | 15 | [![Code Coverage][coverage-badge]][coverage]
|
15 | 16 | [![version][version-badge]][package]
|
16 | 17 | [![downloads][downloads-badge]][npmtrends]
|
17 | 18 | [![MIT License][license-badge]][license]
|
18 | 19 |
|
19 |
| -[](#contributors) |
| 20 | +[](#contributors) |
20 | 21 | [![PRs Welcome][prs-badge]][prs]
|
21 | 22 | [![Code of Conduct][coc-badge]][coc]
|
22 | 23 |
|
23 | 24 | [![Watch on GitHub][github-watch-badge]][github-watch]
|
24 | 25 | [![Star on GitHub][github-star-badge]][github-star]
|
25 | 26 | [![Tweet][twitter-badge]][twitter]
|
| 27 | +<!-- prettier-ignore-end --> |
26 | 28 |
|
27 | 29 | <div align="center">
|
28 | 30 | <a href="https://testingjavascript.com">
|
@@ -102,6 +104,7 @@ when a real user uses it.
|
102 | 104 | - [`within` and `getQueriesForElement` APIs](#within-and-getqueriesforelement-apis)
|
103 | 105 | - [Debugging](#debugging)
|
104 | 106 | - [`prettyDOM`](#prettydom)
|
| 107 | +- [Configuration](#configuration) |
105 | 108 | - [Implementations](#implementations)
|
106 | 109 | - [Using Without Jest](#using-without-jest)
|
107 | 110 | - [FAQ](#faq)
|
@@ -456,6 +459,17 @@ const usernameInputElement = getByTestId(container, 'username-input')
|
456 | 459 | > `data-testid`s from the blog post
|
457 | 460 | > ["Making your UI tests resilient to change"][data-testid-blog-post]
|
458 | 461 |
|
| 462 | +#### Overriding `data-testid` |
| 463 | + |
| 464 | +The `...ByTestId` functions in `dom-testing-library` use the attribute `data-testid` |
| 465 | +by default, following the precedent set by |
| 466 | +[React Native Web](https://github.com/kentcdodds/react-testing-library/issues/1) |
| 467 | +which uses a `testID` prop to emit a `data-testid` attribute on the element, |
| 468 | +and we recommend you adopt that attribute where possible. |
| 469 | +But if you already have an existing codebase that uses a different attribute |
| 470 | +for this purpose, you can override this value via |
| 471 | +`configure({testIdAttribute: 'data-my-test-attribute'})`. |
| 472 | +
|
459 | 473 | ### `wait`
|
460 | 474 |
|
461 | 475 | ```typescript
|
@@ -928,6 +942,19 @@ console.log(prettyDOM(div))
|
928 | 942 |
|
929 | 943 | This function is what also powers [the automatic debugging output described above](#debugging).
|
930 | 944 |
|
| 945 | +## Configuration |
| 946 | + |
| 947 | +The library can be configured via the `configure` function, which accepts: |
| 948 | + |
| 949 | +- a plain JS object; this will be merged into the existing configuration. e.g. `configure({testIdAttribute: 'not-data-testid'})` |
| 950 | +- a function; the function will be given the existing configuration, and should return a plain JS object which will be merged as above, e.g. |
| 951 | + `configure(existingConfig => ({something: [...existingConfig.something, 'extra value for the something array']}))` |
| 952 | + |
| 953 | +Configuration options: |
| 954 | + |
| 955 | +`testIdAttribute`: The attribute used by `getByTestId` and related queries. |
| 956 | +Defaults to `data-testid`. See [`getByTestId`](#getbytestid). |
| 957 | + |
931 | 958 | ## Implementations
|
932 | 959 |
|
933 | 960 | This library was not built to be used on its own. The original implementation
|
@@ -1115,6 +1142,7 @@ Thanks goes to these people ([emoji key][emojis]):
|
1115 | 1142 | | [<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") |
|
1116 | 1143 | | [<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") |
|
1117 | 1144 | | [<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") |
|
| 1145 | +| [<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") | |
1118 | 1146 |
|
1119 | 1147 | <!-- ALL-CONTRIBUTORS-LIST:END -->
|
1120 | 1148 |
|
|
0 commit comments