Skip to content

Commit

Permalink
feat: support the getAll* APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Apr 24, 2018
1 parent a44bb83 commit e386c14
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cypress/fixtures/test-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ <h2>getByTestId</h2>
onclick="this.style.border = '5px solid red'"
/>
</section>
<section>
<h2>getAllByText</h2>
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 1</button>
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 2</button>
</section>
<!-- Prettier unindents the script tag below -->
<script>
document
Expand Down
4 changes: 4 additions & 0 deletions cypress/integration/commands.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ describe('dom-testing-library commands', () => {
it('getByTestId', () => {
cy.getByTestId('image-with-random-alt-tag').click()
})

it('getAllByText', () => {
cy.getAllByText('Jackie Chan').click({multiple: true})
})
})

/* global cy */
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"author": "Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)",
"license": "MIT",
"dependencies": {
"dom-testing-library": "^1.3.0"
"dom-testing-library": "^1.10.0"
},
"devDependencies": {
"cypress": "^2.1.0",
"kcd-scripts": "^0.37.0",
"npm-run-all": "^4.1.2",
"serve": "^6.5.4"
"serve": "^6.5.6"
},
"peerDependencies": {
"cypress": "^2.1.0"
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/__snapshots__/commands.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
exports[`exports expected commands 1`] = `
Array [
"getByPlaceholderText",
"getAllByPlaceholderText",
"getByText",
"getAllByText",
"getByLabelText",
"getAllByLabelText",
"getByAltText",
"getAllByAltText",
"getByTestId",
"getAllByTestId",
]
`;
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {queries, waitForElement} from 'dom-testing-library'

const commands = Object.keys(queries)
.filter(queryName => queryName.startsWith('getBy'))
.filter(
queryName =>
queryName.startsWith('getBy') || queryName.startsWith('getAllBy'),
)
.map(queryName => {
return {
name: queryName,
Expand Down

2 comments on commit e386c14

@sompylasar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kentcdodds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have opened a PR for this. But considering it's not officially released yet 🤷‍♂️

Please sign in to comment.