Skip to content

Commit 16f8c65

Browse files
adrians5jKent C. Dodds
authored and
Kent C. Dodds
committed
fix: use default command timeout value from Cypress config. (#22)
**What**: - fixes #19 **Why**: Developers would expect `cypress-testing-library` commands to respect `defaultCommandTimeout` value (this value can be set via `cypress.json`). **How**: We just replaced the hard-coded `3000` ms with `Cypress.config().defaultCommandTimeout`. **Checklist**: * [x] Documentation N/A * [ ] Tests * [ ] Ready to be merged * [x] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> At this point, I'm just not sure what would be the most appropriate way to test this, any advice? Would it be better to test this with cypress or with jest ? Thanks!
1 parent d782f03 commit 16f8c65

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
"test",
6262
"tool"
6363
]
64+
},
65+
{
66+
"login": "adrian1358",
67+
"name": "Adrian Smijulj",
68+
"avatar_url": "https://avatars0.githubusercontent.com/u/5121148?v=4",
69+
"profile": "https://www.webiny.com",
70+
"contributions": [
71+
"code"
72+
]
6473
}
6574
],
6675
"repoType": "github"

README.md

Lines changed: 3 additions & 3 deletions
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-5-orange.svg?style=flat-square)](#contributors)
19+
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
2020
[![PRs Welcome][prs-badge]][prs]
2121
[![Code of Conduct][coc-badge]][coc]
2222

@@ -100,8 +100,8 @@ Thanks goes to these people ([emoji key][emojis]):
100100

101101
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
102102
<!-- prettier-ignore -->
103-
| [<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") | [<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/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [<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/cypress-testing-library/commits?author=npeterkamps "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Documentation") [🤔](#ideas-npeterkamps "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Tests") | [<img src="https://avatars3.githubusercontent.com/u/4506749?v=4" width="100px;"/><br /><sub><b>Airat Aminev</b></sub>](https://github.com/airato)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Tests") [🔧](#tool-airato "Tools") |
104-
| :---: | :---: | :---: | :---: | :---: |
103+
| [<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") | [<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/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [<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/cypress-testing-library/commits?author=npeterkamps "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Documentation") [🤔](#ideas-npeterkamps "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Tests") | [<img src="https://avatars3.githubusercontent.com/u/4506749?v=4" width="100px;"/><br /><sub><b>Airat Aminev</b></sub>](https://github.com/airato)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Tests") [🔧](#tool-airato "Tools") | [<img src="https://avatars0.githubusercontent.com/u/5121148?v=4" width="100px;"/><br /><sub><b>Adrian Smijulj</b></sub>](https://www.webiny.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=adrian1358 "Code") |
104+
| :---: | :---: | :---: | :---: | :---: | :---: |
105105

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

src/index.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
import {queries, waitForElement} from 'dom-testing-library'
22
import {getContainer} from './utils'
33

4-
const defaults = {
5-
timeout: 3000,
4+
const getDefaultCommandOptions = () => {
5+
return {
6+
timeout: Cypress.config().defaultCommandTimeout,
7+
}
68
}
79

810
const commands = Object.keys(queries).map(queryName => {
911
return {
1012
name: queryName,
1113
command: (...args) => {
1214
const lastArg = args[args.length - 1]
13-
const waitOptions = (typeof lastArg === 'object')
14-
? Object.assign({}, defaults, lastArg)
15-
: defaults
15+
const defaults = getDefaultCommandOptions()
16+
const waitOptions =
17+
typeof lastArg === 'object'
18+
? Object.assign({}, defaults, lastArg)
19+
: defaults
1620

1721
const queryImpl = queries[queryName]
1822
const baseCommandImpl = doc => {
19-
const container = getContainer(waitOptions.container || doc);
20-
return waitForElement(() => queryImpl(container, ...args), Object.assign({}, waitOptions, {
21-
container,
22-
}))
23+
const container = getContainer(waitOptions.container || doc)
24+
return waitForElement(
25+
() => queryImpl(container, ...args),
26+
Object.assign({}, waitOptions, {
27+
container,
28+
}),
29+
)
2330
}
2431
let commandImpl
2532
if (
@@ -43,19 +50,22 @@ const commands = Object.keys(queries).map(queryName => {
4350
)(commandImpl)
4451
return cy
4552
.window({log: false})
46-
.then({ timeout: waitOptions.timeout + 100 }, thenHandler)
53+
.then({timeout: waitOptions.timeout + 100}, thenHandler)
4754
.then(subject => {
4855
Cypress.log({
4956
$el: subject,
5057
name: queryName,
51-
message: args.filter((value) => {
58+
message: args.filter(value => {
5259
if (Array.isArray(value) && value.length === 0) {
53-
return false;
60+
return false
5461
}
55-
if (typeof value === 'object' && Object.keys(value).length === 0) {
56-
return false;
62+
if (
63+
typeof value === 'object' &&
64+
Object.keys(value).length === 0
65+
) {
66+
return false
5767
}
58-
return Boolean(value);
68+
return Boolean(value)
5969
}),
6070
})
6171
return subject

0 commit comments

Comments
 (0)