@@ -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
- ### ` getByTitle(container: HTMLElement, title: ExactTextMatch): HTMLElement `
294
+ ### ` getByTitle `
295
+
296
+ ``` typescript
297
+ getByTitle (
298
+ container : HTMLElement ,
299
+ title : TextMatch ,
300
+ options ?: {
301
+ exact?: boolean = true ,
302
+ }): HTMLElement
303
+ ```
258
304
259
305
This will return the element that has the matching ` title ` attribute.
260
306
@@ -263,7 +309,16 @@ This will return the element that has the matching `title` attribute.
263
309
const deleteElement = getByTitle (container, ' Delete' )
264
310
```
265
311
266
- ### ` getByTestId(container: HTMLElement, text: ExactTextMatch, {exact: boolean = true}): HTMLElement `
312
+ ### ` getByTestId `
313
+
314
+ ``` typescript
315
+ getByTestId (
316
+ container : HTMLElement ,
317
+ text : ExactTextMatch ,
318
+ options ?: {
319
+ exact?: boolean = true ,
320
+ }): HTMLElement `
321
+ ` ` `
267
322
268
323
A shortcut to ` ` container .querySelector (` [data-testid="${yourId }"] ` ) ` ` (and it
269
324
also accepts an [` ExactTextMatch ` ](#exacttextmatch )).
@@ -283,8 +338,6 @@ const usernameInputElement = getByTestId(container, 'username-input')
283
338
284
339
### `wait `
285
340
286
- Defined as:
287
-
288
341
```typescript
289
342
function wait (
290
343
callback ?: () => void ,
@@ -326,8 +379,6 @@ intervals.
326
379
327
380
### ` waitForElement `
328
381
329
- Defined as :
330
-
331
382
``` typescript
332
383
function waitForElement<T >(
333
384
callback ? : () => T | null | undefined ,
@@ -386,7 +437,11 @@ The default `timeout` is `4500ms` which will keep you under
386
437
additions and removals of child elements (including text nodes ) in the ` container ` and any of its descendants .
387
438
It won ' t detect attribute changes unless you add `attributes: true` to the options.
388
439
389
- ### ` fireEvent(node: HTMLElement, event: Event) `
440
+ ### ` fireEvent `
441
+
442
+ ` ` ` typescript
443
+ fireEvent(node: HTMLElement, event: Event)
444
+ ` ` `
390
445
391
446
Fire DOM events .
392
447
@@ -401,7 +456,11 @@ fireEvent(
401
456
)
402
457
` ` `
403
458
404
- #### ` fireEvent[eventName](node: HTMLElement, eventProperties: Object) `
459
+ #### ` fireEvent[eventName] `
460
+
461
+ ` ` ` typescript
462
+ fireEvent[eventName](node: HTMLElement, eventProperties: Object)
463
+ ` ` `
405
464
406
465
Convenience methods for firing DOM events . Check out
407
466
[src /events .js ](https :// github.com/kentcdodds/dom-testing-library/blob/master/src/events.js)
@@ -414,7 +473,11 @@ fireEvent.click(getElementByText('Submit'), rightClick)
414
473
// default ` button ` property for click events is set to ` 0 ` which is a left click.
415
474
` ` `
416
475
417
- #### ` getNodeText(node: HTMLElement) `
476
+ #### ` getNodeText `
477
+
478
+ ` ` ` typescript
479
+ getNodeText(node: HTMLElement)
480
+ ` ` `
418
481
419
482
Returns the complete text content of a html element , removing any extra
420
483
whitespace . The intention is to treat text in nodes exactly as how it is
0 commit comments