@@ -72,14 +72,14 @@ when a real user uses it.
72
72
73
73
* [ Installation] ( #installation )
74
74
* [ Usage] ( #usage )
75
- * [ ` getByLabelText(container: HTMLElement, text: TextMatch, options: {selector: string = '*', exact: boolean = true}): HTMLElement ` ] ( #getbylabeltextcontainer-htmlelement-text-textmatch-options-selector-string---exact-boolean--true-htmlelement )
76
- * [ ` getByPlaceholderText(container: HTMLElement, text: TextMatch, {exact: boolean = true}): HTMLElement ` ] ( #getbyplaceholdertextcontainer-htmlelement-text-textmatch-exact-boolean--true-htmlelement )
77
- * [ ` getByText(container: HTMLElement, text: TextMatch, {exact: boolean = true}): HTMLElement ` ] ( #getbytextcontainer-htmlelement-text-textmatch-exact-boolean--true-htmlelement )
78
- * [ ` getByAltText(container: HTMLElement, text: TextMatch, {exact: boolean = true}): HTMLElement ` ] ( #getbyalttextcontainer-htmlelement-text-textmatch-exact-boolean--true-htmlelement )
79
- * [ ` getByTestId(container: HTMLElement, text: ExactTextMatch, {exact: boolean = true}): HTMLElement ` ] ( #getbytestidcontainer-htmlelement-text-exacttextmatch-exact-boolean--true-htmlelement )
75
+ * [ ` getByLabelText ` ] ( #getbylabeltext )
76
+ * [ ` getByPlaceholderText ` ] ( #getbyplaceholdertext )
77
+ * [ ` getByText ` ] ( #getbytext )
78
+ * [ ` getByAltText ` ] ( #getbyalttext )
79
+ * [ ` getByTestId ` ] ( #getbytestid )
80
80
* [ ` wait ` ] ( #wait )
81
81
* [ ` waitForElement ` ] ( #waitforelement )
82
- * [ ` fireEvent(node: HTMLElement, event: Event) ` ] ( #fireeventnode-htmlelement-event-event )
82
+ * [ ` fireEvent ` ] ( #fireevent )
83
83
* [ Custom Jest Matchers] ( #custom-jest-matchers )
84
84
* [ Using other assertion libraries] ( #using-other-assertion-libraries )
85
85
* [ ` TextMatch ` ] ( #textmatch )
@@ -182,7 +182,17 @@ test('examples of some things', async () => {
182
182
})
183
183
```
184
184
185
- ### ` getByLabelText(container: HTMLElement, text: TextMatch, options: {selector: string = '*', exact: boolean = true}): HTMLElement `
185
+ ### ` getByLabelText `
186
+
187
+ ``` typescript
188
+ getByLabelText (
189
+ container : HTMLElement ,
190
+ text : TextMatch ,
191
+ options ?: {
192
+ selector?: string = ' *' ,
193
+ exact?: boolean = true ,
194
+ }): HTMLElement
195
+ ```
186
196
187
197
This will search for the label that matches the given [ ` TextMatch ` ] ( #textmatch ) ,
188
198
then find the element associated with that label.
@@ -217,7 +227,16 @@ const inputNode = getByLabelText(container, 'username', {selector: 'input'})
217
227
> want this behavior (for example you wish to assert that it doesn't exist),
218
228
> then use ` queryByLabelText ` instead.
219
229
220
- ### ` getByPlaceholderText(container: HTMLElement, text: TextMatch, {exact: boolean = true}): HTMLElement `
230
+ ### ` getByPlaceholderText `
231
+
232
+ ``` typescript
233
+ getByPlaceholderText (
234
+ container : HTMLElement ,
235
+ text : TextMatch ,
236
+ options ?: {
237
+ exact?: boolean = true ,
238
+ }): HTMLElement
239
+ ```
221
240
222
241
This will search for all elements with a placeholder attribute and find one
223
242
that matches the given [ ` TextMatch ` ] ( #textmatch ) .
@@ -230,7 +249,16 @@ const inputNode = getByPlaceholderText(container, 'Username')
230
249
> NOTE: a placeholder is not a good substitute for a label so you should
231
250
> generally use ` getByLabelText ` instead.
232
251
233
- ### ` getByText(container: HTMLElement, text: TextMatch, {exact: boolean = true}): HTMLElement `
252
+ ### ` getByText `
253
+
254
+ ``` typescript
255
+ getByText (
256
+ container : HTMLElement ,
257
+ text : TextMatch ,
258
+ options ?: {
259
+ exact?: boolean = true ,
260
+ }): HTMLElement
261
+ ```
234
262
235
263
This will search for all elements that have a text node with ` textContent `
236
264
matching the given [ ` TextMatch ` ] ( #textmatch ) .
@@ -240,7 +268,16 @@ matching the given [`TextMatch`](#textmatch).
240
268
const aboutAnchorNode = getByText (container, ' about' )
241
269
```
242
270
243
- ### ` getByAltText(container: HTMLElement, text: TextMatch, {exact: boolean = true}): HTMLElement `
271
+ ### ` getByAltText `
272
+
273
+ ``` typescript
274
+ getByAltText (
275
+ container : HTMLElement ,
276
+ text : TextMatch ,
277
+ options ?: {
278
+ exact?: boolean = true ,
279
+ }): HTMLElement
280
+ ```
244
281
245
282
This will return the element (normally an ` <img> ` ) that has the given ` alt `
246
283
text. Note that it only supports elements which accept an ` alt ` attribute:
@@ -254,7 +291,16 @@ and [`<area>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area)
254
291
const incrediblesPosterImg = getByAltText (container, / incredibles. * poster$ / i )
255
292
```
256
293
257
- ### ` getByTestId(container: HTMLElement, text: ExactTextMatch, {exact: boolean = true}): HTMLElement `
294
+ ### ` getByTestId `
295
+
296
+ ``` typescript
297
+ getByTestId (
298
+ container : HTMLElement ,
299
+ text : ExactTextMatch ,
300
+ options ?: {
301
+ exact?: boolean = true ,
302
+ }): HTMLElement `
303
+ ` ` `
258
304
259
305
A shortcut to ` ` container .querySelector (` [data-testid="${yourId }"] ` ) ` ` (and it
260
306
also accepts an [` ExactTextMatch ` ](#exacttextmatch )).
@@ -274,8 +320,6 @@ const usernameInputElement = getByTestId(container, 'username-input')
274
320
275
321
### `wait `
276
322
277
- Defined as:
278
-
279
323
```typescript
280
324
function wait (
281
325
callback ?: () => void ,
@@ -317,8 +361,6 @@ intervals.
317
361
318
362
### ` waitForElement `
319
363
320
- Defined as :
321
-
322
364
``` typescript
323
365
function waitForElement<T >(
324
366
callback ? : () => T | null | undefined ,
@@ -377,7 +419,11 @@ The default `timeout` is `4500ms` which will keep you under
377
419
additions and removals of child elements (including text nodes ) in the ` container ` and any of its descendants .
378
420
It won ' t detect attribute changes unless you add `attributes: true` to the options.
379
421
380
- ### ` fireEvent(node: HTMLElement, event: Event) `
422
+ ### ` fireEvent `
423
+
424
+ ` ` ` typescript
425
+ fireEvent(node: HTMLElement, event: Event)
426
+ ` ` `
381
427
382
428
Fire DOM events .
383
429
@@ -392,7 +438,11 @@ fireEvent(
392
438
)
393
439
` ` `
394
440
395
- #### ` fireEvent[eventName](node: HTMLElement, eventProperties: Object) `
441
+ #### ` fireEvent[eventName] `
442
+
443
+ ` ` ` typescript
444
+ fireEvent[eventName](node: HTMLElement, eventProperties: Object)
445
+ ` ` `
396
446
397
447
Convenience methods for firing DOM events . Check out
398
448
[src /events .js ](https :// github.com/kentcdodds/dom-testing-library/blob/master/src/events.js)
@@ -405,7 +455,11 @@ fireEvent.click(getElementByText('Submit'), rightClick)
405
455
// default ` button ` property for click events is set to ` 0 ` which is a left click.
406
456
` ` `
407
457
408
- #### ` getNodeText(node: HTMLElement) `
458
+ #### ` getNodeText `
459
+
460
+ ` ` ` typescript
461
+ getNodeText(node: HTMLElement)
462
+ ` ` `
409
463
410
464
Returns the complete text content of a html element , removing any extra
411
465
whitespace . The intention is to treat text in nodes exactly as how it is
0 commit comments