@@ -76,12 +76,14 @@ when a real user uses it.
76
76
* [ ` getByPlaceholderText(container: HTMLElement, text: TextMatch): HTMLElement ` ] ( #getbyplaceholdertextcontainer-htmlelement-text-textmatch-htmlelement )
77
77
* [ ` getByText(container: HTMLElement, text: TextMatch): HTMLElement ` ] ( #getbytextcontainer-htmlelement-text-textmatch-htmlelement )
78
78
* [ ` getByAltText(container: HTMLElement, text: TextMatch): HTMLElement ` ] ( #getbyalttextcontainer-htmlelement-text-textmatch-htmlelement )
79
+ * [ ` getByTestId(container: HTMLElement, text: ExactTextMatch): HTMLElement ` ] ( #getbytestidcontainer-htmlelement-text-exacttextmatch-htmlelement )
79
80
* [ ` wait ` ] ( #wait )
80
81
* [ ` waitForElement ` ] ( #waitforelement )
81
82
* [ ` fireEvent(node: HTMLElement, event: Event) ` ] ( #fireeventnode-htmlelement-event-event )
82
83
* [ Custom Jest Matchers] ( #custom-jest-matchers )
83
84
* [ Using other assertion libraries] ( #using-other-assertion-libraries )
84
85
* [ ` TextMatch ` ] ( #textmatch )
86
+ * [ ExactTextMatch] ( #exacttextmatch )
85
87
* [ ` query ` APIs] ( #query-apis )
86
88
* [ ` queryAll ` and ` getAll ` APIs] ( #queryall-and-getall-apis )
87
89
* [ ` bindElementToQueries ` ] ( #bindelementtoqueries )
@@ -248,10 +250,10 @@ and [`<area>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area)
248
250
const incrediblesPosterImg = getByAltText (container, / incredibles. * poster$ / i )
249
251
```
250
252
251
- #### ` getByTestId(container: HTMLElement, text: TextMatch ): HTMLElement `
253
+ ### ` getByTestId(container: HTMLElement, text: ExactTextMatch ): HTMLElement `
252
254
253
255
A shortcut to `` container.querySelector(`[data-testid="${yourId}"]`) `` (and it
254
- also accepts a [ ` TextMatch ` ] ( #textmatch ) ).
256
+ also accepts an [ ` ExactTextMatch ` ] ( #exacttextmatch ) ).
255
257
256
258
``` javascript
257
259
// <input data-testid="username-input" />
@@ -477,6 +479,25 @@ getByText(container, (content, element) => {
477
479
})
478
480
` ` `
479
481
482
+ ### ExactTextMatch
483
+
484
+ Some APIs use ExactTextMatch , which is the same as TextMatch but case -sensitive
485
+ and does not match substrings ; however , regexes and functions are also accepted
486
+ for custom matching .
487
+
488
+ ` ` ` js
489
+ // <button data-testid="submit-button">Go</button>
490
+
491
+ // all of the following will find the button
492
+ getByTestId(container, 'submit-button') // exact match
493
+ getByTestId(container, /submit*/) // regex match
494
+ getByTestId(container, content => content.startsWith('submit')) // function
495
+
496
+ // all of the following will NOT find the button
497
+ getByTestId(container, 'submit-') // no substrings
498
+ getByTestId(container, 'Submit-Button') // case-sensitive
499
+ ` ` `
500
+
480
501
## ` query ` APIs
481
502
482
503
Each of the ` get ` APIs listed in [the ' Usage' ](#usage ) section above have a
0 commit comments