Skip to content

Commit

Permalink
fix: use getBy, not queryBy, to fail on missing element (#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sompylasar authored and Kent C. Dodds committed Apr 7, 2018
1 parent 5d39f66 commit 5106558
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
13 changes: 12 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
"infra",
"test"
]
},
{
"login": "sompylasar",
"name": "Ivan Babak",
"avatar_url": "https://avatars2.githubusercontent.com/u/498274?v=4",
"profile": "https://sompylasar.github.io",
"contributions": [
"code",
"ideas"
]
}
]
],
"repoType": "github"
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]

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

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

<!-- prettier-ignore -->
| [<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://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") |
| :---: | :---: |

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

Expand Down
2 changes: 1 addition & 1 deletion src/add-commands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {commands} from './'

commands.forEach(({command, name}) => {
commands.forEach(({name, command}) => {
Cypress.Commands.add(name, command)
})

Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import {queries} from 'dom-testing-library'

const commands = Object.keys(queries)
.filter(queryName => queryName.startsWith('query'))
.filter(queryName => queryName.startsWith('getBy'))
.map(queryName => {
const commandName = queryName.replace(/^query/, 'get')
return {
name: commandName,
name: queryName,
command: (...args) => {
const fn = new Function(
'args',
'query',
'getCommandWaiter',
`
return function Command__${commandName}({document}) {
return function Command__${queryName}({document}) {
return getCommandWaiter(document, () => query(document, ...args))();
};
`,
Expand Down

0 comments on commit 5106558

Please sign in to comment.