Skip to content

Commit

Permalink
fix: use default command timeout value from Cypress config. (#22)
Browse files Browse the repository at this point in the history
**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!
  • Loading branch information
adrians5j authored and Kent C. Dodds committed Nov 8, 2018
1 parent d782f03 commit 16f8c65
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
"test",
"tool"
]
},
{
"login": "adrian1358",
"name": "Adrian Smijulj",
"avatar_url": "https://avatars0.githubusercontent.com/u/5121148?v=4",
"profile": "https://www.webiny.com",
"contributions": [
"code"
]
}
],
"repoType": "github"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]

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

Expand Down Expand Up @@ -100,8 +100,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://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://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") |
| :---: | :---: | :---: | :---: | :---: | :---: |

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

Expand Down
40 changes: 25 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import {queries, waitForElement} from 'dom-testing-library'
import {getContainer} from './utils'

const defaults = {
timeout: 3000,
const getDefaultCommandOptions = () => {
return {
timeout: Cypress.config().defaultCommandTimeout,
}
}

const commands = Object.keys(queries).map(queryName => {
return {
name: queryName,
command: (...args) => {
const lastArg = args[args.length - 1]
const waitOptions = (typeof lastArg === 'object')
? Object.assign({}, defaults, lastArg)
: defaults
const defaults = getDefaultCommandOptions()
const waitOptions =
typeof lastArg === 'object'
? Object.assign({}, defaults, lastArg)
: defaults

const queryImpl = queries[queryName]
const baseCommandImpl = doc => {
const container = getContainer(waitOptions.container || doc);
return waitForElement(() => queryImpl(container, ...args), Object.assign({}, waitOptions, {
container,
}))
const container = getContainer(waitOptions.container || doc)
return waitForElement(
() => queryImpl(container, ...args),
Object.assign({}, waitOptions, {
container,
}),
)
}
let commandImpl
if (
Expand All @@ -43,19 +50,22 @@ const commands = Object.keys(queries).map(queryName => {
)(commandImpl)
return cy
.window({log: false})
.then({ timeout: waitOptions.timeout + 100 }, thenHandler)
.then({timeout: waitOptions.timeout + 100}, thenHandler)
.then(subject => {
Cypress.log({
$el: subject,
name: queryName,
message: args.filter((value) => {
message: args.filter(value => {
if (Array.isArray(value) && value.length === 0) {
return false;
return false
}
if (typeof value === 'object' && Object.keys(value).length === 0) {
return false;
if (
typeof value === 'object' &&
Object.keys(value).length === 0
) {
return false
}
return Boolean(value);
return Boolean(value)
}),
})
return subject
Expand Down

0 comments on commit 16f8c65

Please sign in to comment.