Skip to content

Commit e386c14

Browse files
author
Kent C. Dodds
committed
feat: support the getAll* APIs
1 parent a44bb83 commit e386c14

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

cypress/fixtures/test-app/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ <h2>getByTestId</h2>
5151
onclick="this.style.border = '5px solid red'"
5252
/>
5353
</section>
54+
<section>
55+
<h2>getAllByText</h2>
56+
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 1</button>
57+
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 2</button>
58+
</section>
5459
<!-- Prettier unindents the script tag below -->
5560
<script>
5661
document

cypress/integration/commands.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ describe('dom-testing-library commands', () => {
2727
it('getByTestId', () => {
2828
cy.getByTestId('image-with-random-alt-tag').click()
2929
})
30+
31+
it('getAllByText', () => {
32+
cy.getAllByText('Jackie Chan').click({multiple: true})
33+
})
3034
})
3135

3236
/* global cy */

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
4040
"license": "MIT",
4141
"dependencies": {
42-
"dom-testing-library": "^1.3.0"
42+
"dom-testing-library": "^1.10.0"
4343
},
4444
"devDependencies": {
4545
"cypress": "^2.1.0",
4646
"kcd-scripts": "^0.37.0",
4747
"npm-run-all": "^4.1.2",
48-
"serve": "^6.5.4"
48+
"serve": "^6.5.6"
4949
},
5050
"peerDependencies": {
5151
"cypress": "^2.1.0"

src/__tests__/__snapshots__/commands.js.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
exports[`exports expected commands 1`] = `
44
Array [
55
"getByPlaceholderText",
6+
"getAllByPlaceholderText",
67
"getByText",
8+
"getAllByText",
79
"getByLabelText",
10+
"getAllByLabelText",
811
"getByAltText",
12+
"getAllByAltText",
913
"getByTestId",
14+
"getAllByTestId",
1015
]
1116
`;

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import {queries, waitForElement} from 'dom-testing-library'
22

33
const commands = Object.keys(queries)
4-
.filter(queryName => queryName.startsWith('getBy'))
4+
.filter(
5+
queryName =>
6+
queryName.startsWith('getBy') || queryName.startsWith('getAllBy'),
7+
)
58
.map(queryName => {
69
return {
710
name: queryName,

0 commit comments

Comments
 (0)