Skip to content

Commit 8c9c766

Browse files
committed
Pass all args to queryImpl, pass all args with some defaults to waitForElement.
1 parent d3925c9 commit 8c9c766

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import {queries, waitForElement} from 'dom-testing-library'
22

3+
const defaults = {
4+
timeout: 3000,
5+
}
6+
37
const commands = Object.keys(queries).map(queryName => {
48
return {
59
name: queryName,
6-
command: (cy, text, options = {}) => {
7-
const { timeout = 3000 } = options;
10+
command: (cy, ...args) => {
11+
const lastArg = args[args.length - 1]
12+
const waitOptions = (typeof lastArg === 'object')
13+
? Object.assign({}, defaults, lastArg)
14+
: defaults
15+
816
const queryImpl = queries[queryName]
917
const baseCommandImpl = doc =>
10-
waitForElement(() => queryImpl(doc, text, options), {
18+
waitForElement(() => queryImpl(doc, ...args), Object.assign({}, waitOptions, {
1119
container: doc,
12-
timeout,
13-
})
20+
}))
1421
let commandImpl
1522
if (
1623
queryName.startsWith('queryBy') ||
@@ -33,12 +40,12 @@ const commands = Object.keys(queries).map(queryName => {
3340
)(commandImpl)
3441
return cy
3542
.window({log: false})
36-
.then({ timeout: timeout + 100 }, thenHandler)
43+
.then({ timeout: waitOptions.timeout + 100 }, thenHandler)
3744
.then(subject => {
3845
Cypress.log({
3946
$el: subject,
4047
name: queryName,
41-
message: [text, options].filter((value) => {
48+
message: args.filter((value) => {
4249
if (Array.isArray(value) && value.length === 0) {
4350
return false;
4451
}

0 commit comments

Comments
 (0)