11import { queries , waitForElement } from 'dom-testing-library'
22
3+ const defaults = {
4+ timeout : 3000 ,
5+ }
6+
37const 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