Skip to content

Commit 5106558

Browse files
sompylasarKent C. Dodds
authored andcommitted
fix: use getBy, not queryBy, to fail on missing element (#1)
* fix(add-commands): reorder forEach arg fields for consistency * fix(commands): use getBy, not queryBy, to fail on missing element BREAKING CHANGE: The queries will now throw a useful message and fail the test if the queried element is missing. * docs(contributors): add sompylasar
1 parent 5d39f66 commit 5106558

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

.all-contributorsrc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
"infra",
1919
"test"
2020
]
21+
},
22+
{
23+
"login": "sompylasar",
24+
"name": "Ivan Babak",
25+
"avatar_url": "https://avatars2.githubusercontent.com/u/498274?v=4",
26+
"profile": "https://sompylasar.github.io",
27+
"contributions": [
28+
"code",
29+
"ideas"
30+
]
2131
}
22-
]
32+
],
33+
"repoType": "github"
2334
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![downloads][downloads-badge]][npmtrends]
1313
[![MIT License][license-badge]][license]
1414

15-
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
15+
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)
1616
[![PRs Welcome][prs-badge]][prs]
1717
[![Code of Conduct][coc-badge]][coc]
1818

@@ -74,8 +74,8 @@ Thanks goes to these people ([emoji key][emojis]):
7474
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
7575

7676
<!-- prettier-ignore -->
77-
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Tests") |
78-
| :---: |
77+
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Tests") | [<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/cypress-testing-library/commits?author=sompylasar "Code") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") |
78+
| :---: | :---: |
7979

8080
<!-- ALL-CONTRIBUTORS-LIST:END -->
8181

src/add-commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {commands} from './'
22

3-
commands.forEach(({command, name}) => {
3+
commands.forEach(({name, command}) => {
44
Cypress.Commands.add(name, command)
55
})
66

src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import {queries} from 'dom-testing-library'
22

33
const commands = Object.keys(queries)
4-
.filter(queryName => queryName.startsWith('query'))
4+
.filter(queryName => queryName.startsWith('getBy'))
55
.map(queryName => {
6-
const commandName = queryName.replace(/^query/, 'get')
76
return {
8-
name: commandName,
7+
name: queryName,
98
command: (...args) => {
109
const fn = new Function(
1110
'args',
1211
'query',
1312
'getCommandWaiter',
1413
`
15-
return function Command__${commandName}({document}) {
14+
return function Command__${queryName}({document}) {
1615
return getCommandWaiter(document, () => query(document, ...args))();
1716
};
1817
`,

0 commit comments

Comments
 (0)