Skip to content

Commit 7aed39f

Browse files
JonathanStoyeKent C. Dodds
authored and
Kent C. Dodds
committed
chore: update documentation (testing-library#48)
* chore: update contributors * chore(readme): update to reflect the api
1 parent fd0c18c commit 7aed39f

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

.all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@
220220
"code",
221221
"test"
222222
]
223+
},
224+
{
225+
"login": "JonathanStoye",
226+
"name": "Jonathan Stoye",
227+
"avatar_url": "https://avatars2.githubusercontent.com/u/21689428?v=4",
228+
"profile": "http://jonathanstoye.de",
229+
"contributions": [
230+
"doc"
231+
]
223232
}
224233
]
225234
}

README.md

+43-39
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[![downloads][downloads-badge]][npmtrends]
1717
[![MIT License][license-badge]][license]
1818

19-
[![All Contributors](https://img.shields.io/badge/all_contributors-21-orange.svg?style=flat-square)](#contributors)
19+
[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors)
2020
[![PRs Welcome][prs-badge]][prs]
2121
[![Code of Conduct][coc-badge]][coc]
2222

@@ -67,37 +67,36 @@ when a real user uses it.
6767
## Table of Contents
6868

6969
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
70-
7170
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
7271

73-
* [Installation](#installation)
74-
* [Usage](#usage)
75-
* [`getByLabelText`](#getbylabeltext)
76-
* [`getByPlaceholderText`](#getbyplaceholdertext)
77-
* [`getByText`](#getbytext)
78-
* [`getByAltText`](#getbyalttext)
79-
* [`getByTitle`](#getbytitle)
80-
* [`getByValue`](#getbyvalue)
81-
* [`getByTestId`](#getbytestid)
82-
* [`wait`](#wait)
83-
* [`waitForElement`](#waitforelement)
84-
* [`fireEvent`](#fireevent)
85-
* [Custom Jest Matchers](#custom-jest-matchers)
86-
* [Using other assertion libraries](#using-other-assertion-libraries)
87-
* [`TextMatch`](#textmatch)
88-
* [Precision](#precision)
89-
* [TextMatch Examples](#textmatch-examples)
90-
* [`query` APIs](#query-apis)
91-
* [`queryAll` and `getAll` APIs](#queryall-and-getall-apis)
92-
* [`getQueriesForElement`](#getqueriesforelement)
93-
* [Debugging](#debugging)
94-
* [`prettyDOM`](#prettydom)
95-
* [Implementations](#implementations)
96-
* [FAQ](#faq)
97-
* [Other Solutions](#other-solutions)
98-
* [Guiding Principles](#guiding-principles)
99-
* [Contributors](#contributors)
100-
* [LICENSE](#license)
72+
- [Installation](#installation)
73+
- [Usage](#usage)
74+
- [`getByLabelText`](#getbylabeltext)
75+
- [`getByPlaceholderText`](#getbyplaceholdertext)
76+
- [`getByText`](#getbytext)
77+
- [`getByAltText`](#getbyalttext)
78+
- [`getByTitle`](#getbytitle)
79+
- [`getByValue`](#getbyvalue)
80+
- [`getByTestId`](#getbytestid)
81+
- [`wait`](#wait)
82+
- [`waitForElement`](#waitforelement)
83+
- [`fireEvent`](#fireevent)
84+
- [Custom Jest Matchers](#custom-jest-matchers)
85+
- [Using other assertion libraries](#using-other-assertion-libraries)
86+
- [`TextMatch`](#textmatch)
87+
- [Precision](#precision)
88+
- [TextMatch Examples](#textmatch-examples)
89+
- [`query` APIs](#query-apis)
90+
- [`queryAll` and `getAll` APIs](#queryall-and-getall-apis)
91+
- [`getQueriesForElement`](#getqueriesforelement)
92+
- [Debugging](#debugging)
93+
- [`prettyDOM`](#prettydom)
94+
- [Implementations](#implementations)
95+
- [FAQ](#faq)
96+
- [Other Solutions](#other-solutions)
97+
- [Guiding Principles](#guiding-principles)
98+
- [Contributors](#contributors)
99+
- [LICENSE](#license)
101100

102101
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
103102

@@ -114,8 +113,8 @@ npm install --save-dev dom-testing-library
114113

115114
Note:
116115

117-
* Each of the `get` APIs below have a matching [`getAll`](#queryall-and-getall-apis) API that returns all elements instead of just the first one, and [`query`](#query-apis)/[`getAll`](#queryall-and-getall-apis) that return `null`/`[]` instead of throwing an error.
118-
* See [TextMatch](#textmatch) for details on the `exact`, `trim`, and `collapseWhitespace` options.
116+
- Each of the `get` APIs below have a matching [`getAll`](#queryall-and-getall-apis) API that returns all elements instead of just the first one, and [`query`](#query-apis)/[`getAll`](#queryall-and-getall-apis) that return `null`/`[]` instead of throwing an error.
117+
- See [TextMatch](#textmatch) for details on the `exact`, `trim`, and `collapseWhitespace` options.
119118

120119
```javascript
121120
// src/__tests__/example.js
@@ -262,6 +261,7 @@ getByText(
262261
container: HTMLElement,
263262
text: TextMatch,
264263
options?: {
264+
selector?: string = '*',
265265
exact?: boolean = true,
266266
collapseWhitespace?: boolean = true,
267267
trim?: boolean = true,
@@ -276,6 +276,8 @@ matching the given [`TextMatch`](#textmatch).
276276
const aboutAnchorNode = getByText(container, 'about')
277277
```
278278

279+
> NOTE: see [`getbylabeltext`](#getbylabeltext) for more details on how and when to use the `selector` option
280+
279281
### `getByAltText`
280282

281283
```typescript
@@ -559,7 +561,7 @@ If you're not using jest, you may be able to find a similar set of custom
559561
assertions for your library of choice. Here's a list of alternatives to jest-dom
560562
for other popular assertion libraries:
561563

562-
* [chai-dom](https://github.com/nathanboktae/chai-dom)
564+
- [chai-dom](https://github.com/nathanboktae/chai-dom)
563565

564566
If you're aware of some other alternatives, please [make a pull request][prs]
565567
and add it here!
@@ -574,13 +576,13 @@ Several APIs accept a `TextMatch` which can be a `string`, `regex` or a
574576
Some APIs accept an object as the final argument that can contain options that
575577
affect the precision of string matching:
576578

577-
* `exact`: Defaults to `true`; matches full strings, case-sensitive. When false,
579+
- `exact`: Defaults to `true`; matches full strings, case-sensitive. When false,
578580
matches substrings and is not case-sensitive.
579-
* `exact` has no effect on `regex` or `function` arguments.
580-
* In most cases using a regex instead of a string gives you more control over
581+
- `exact` has no effect on `regex` or `function` arguments.
582+
- In most cases using a regex instead of a string gives you more control over
581583
fuzzy matching and should be preferred over `{ exact: false }`.
582-
* `trim`: Defaults to `true`; trim leading and trailing whitespace.
583-
* `collapseWhitespace`: Defaults to `true`. Collapses inner whitespace (newlines, tabs, repeated spaces) into a single space.
584+
- `trim`: Defaults to `true`; trim leading and trailing whitespace.
585+
- `collapseWhitespace`: Defaults to `true`. Collapses inner whitespace (newlines, tabs, repeated spaces) into a single space.
584586

585587
### TextMatch Examples
586588

@@ -717,7 +719,7 @@ of these utilities was in the `react-testing-library`.
717719

718720
Implementations include:
719721

720-
* [`react-testing-library`](https://github.com/kentcdodds/react-testing-library)
722+
- [`react-testing-library`](https://github.com/kentcdodds/react-testing-library)
721723

722724
## FAQ
723725

@@ -862,6 +864,8 @@ Thanks goes to these people ([emoji key][emojis]):
862864
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
863865
| [<img src="https://avatars1.githubusercontent.com/u/1241511?s=460&v=4" width="100px;"/><br /><sub><b>Anto Aravinth</b></sub>](https://github.com/antoaravinth)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Tests") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=antoaravinth "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3462296?v=4" width="100px;"/><br /><sub><b>Jonah Moses</b></sub>](https://github.com/JonahMoses)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JonahMoses "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Tests") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=lgandecki "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Asompylasar "Bug reports") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=sompylasar "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/4439618?v=4" width="100px;"/><br /><sub><b>Jesse Day</b></sub>](https://github.com/jday3)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jday3 "Code") | [<img src="https://avatars0.githubusercontent.com/u/15199?v=4" width="100px;"/><br /><sub><b>Ernesto García</b></sub>](http://gnapse.github.io)<br />[💬](#question-gnapse "Answering Questions") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=gnapse "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/2747424?v=4" width="100px;"/><br /><sub><b>Josef Maxx Blake</b></sub>](http://jomaxx.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=jomaxx "Tests") |
864866
| [<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") |
867+
| [<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") |
868+
865869
<!-- ALL-CONTRIBUTORS-LIST:END -->
866870

867871
This project follows the [all-contributors][all-contributors] specification.

0 commit comments

Comments
 (0)