1
1
import { queries , waitForElement } from 'dom-testing-library'
2
2
3
+ const defaults = {
4
+ timeout : 3000 ,
5
+ }
6
+
3
7
const commands = Object . keys ( queries ) . map ( queryName => {
4
8
return {
5
9
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
+
8
16
const queryImpl = queries [ queryName ]
9
17
const baseCommandImpl = doc =>
10
- waitForElement ( ( ) => queryImpl ( doc , text , options ) , {
18
+ waitForElement ( ( ) => queryImpl ( doc , ... args ) , Object . assign ( { } , waitOptions , {
11
19
container : doc ,
12
- timeout,
13
- } )
20
+ } ) )
14
21
let commandImpl
15
22
if (
16
23
queryName . startsWith ( 'queryBy' ) ||
@@ -33,12 +40,12 @@ const commands = Object.keys(queries).map(queryName => {
33
40
) ( commandImpl )
34
41
return cy
35
42
. window ( { log : false } )
36
- . then ( { timeout : timeout + 100 } , thenHandler )
43
+ . then ( { timeout : waitOptions . timeout + 100 } , thenHandler )
37
44
. then ( subject => {
38
45
Cypress . log ( {
39
46
$el : subject ,
40
47
name : queryName ,
41
- message : [ text , options ] . filter ( ( value ) => {
48
+ message : args . filter ( ( value ) => {
42
49
if ( Array . isArray ( value ) && value . length === 0 ) {
43
50
return false ;
44
51
}
0 commit comments