@@ -64,7 +64,7 @@ namespace CypressIsCyTests {
6464
6565declare namespace Cypress {
6666 interface Chainable {
67- newCommand : ( arg : string ) => void
67+ newCommand : ( arg : string ) => Chainable < number >
6868 }
6969}
7070
@@ -74,20 +74,106 @@ namespace CypressCommandsTests {
7474 arg
7575 return
7676 } )
77- Cypress . Commands . add ( 'newCommand' , { prevSubject : true } , ( arg ) => {
77+ Cypress . Commands . add ( 'newCommand' , ( arg ) => {
7878 // $ExpectType string
7979 arg
80+ } )
81+ Cypress . Commands . add ( 'newCommand' , function ( arg ) {
82+ this // $ExpectType Context
83+ arg // $ExpectType string
84+ } )
85+ Cypress . Commands . add ( 'newCommand' , { prevSubject : true } , ( subject , arg ) => {
86+ subject // $ExpectType unknown
87+ arg // $ExpectType string
8088 return
8189 } )
82- Cypress . Commands . add ( 'newCommand' , ( arg ) => {
83- // $ExpectType string
84- arg
85- return new Promise ( ( resolve ) => { } )
90+ Cypress . Commands . add ( 'newCommand' , { prevSubject : false } , ( arg ) => {
91+ arg // $ExpectType string
92+ return
93+ } )
94+ Cypress . Commands . add ( 'newCommand' , { prevSubject : 'optional' } , ( subject , arg ) => {
95+ subject // $ExpectType unknown
96+ arg // $ExpectType string
97+ return
8698 } )
87- Cypress . Commands . overwrite ( 'newCommand' , ( arg ) => {
99+ Cypress . Commands . add ( 'newCommand' , { prevSubject : 'optional' } , ( subject , arg ) => {
100+ subject // $ExpectType unknown
101+ arg // $ExpectType string
102+ } )
103+ Cypress . Commands . add ( 'newCommand' , { prevSubject : [ 'optional' ] } , ( subject , arg ) => {
104+ subject // $ExpectType unknown
105+ arg // $ExpectType string
106+ } )
107+ Cypress . Commands . add ( 'newCommand' , { prevSubject : 'document' } , ( subject , arg ) => {
108+ subject // $ExpectType Document
109+ arg // $ExpectType string
110+ } )
111+ Cypress . Commands . add ( 'newCommand' , { prevSubject : 'window' } , ( subject , arg ) => {
112+ subject // $ExpectType Window
113+ arg // $ExpectType string
114+ } )
115+ Cypress . Commands . add ( 'newCommand' , { prevSubject : 'element' } , ( subject , arg ) => {
116+ subject // $ExpectType JQuery<HTMLElement>
117+ arg // $ExpectType string
118+ } )
119+ Cypress . Commands . add ( 'newCommand' , { prevSubject : [ 'element' ] } , ( subject , arg ) => {
120+ subject // $ExpectType JQuery<HTMLElement>
121+ arg // $ExpectType string
122+ } )
123+ Cypress . Commands . add ( 'newCommand' , { prevSubject : [ 'element' , 'document' , 'window' ] } , ( subject , arg ) => {
124+ if ( subject instanceof Window ) {
125+ subject // $ExpectType Window
126+ } else if ( subject instanceof Document ) {
127+ subject // $ExpectType Document
128+ } else {
129+ subject // $ExpectType JQuery<HTMLElement>
130+ }
131+ arg // $ExpectType string
132+ } )
133+ Cypress . Commands . add ( 'newCommand' , { prevSubject : [ 'window' , 'document' , 'optional' , 'element' ] } , ( subject , arg ) => {
134+ if ( subject instanceof Window ) {
135+ subject // $ExpectType Window
136+ } else if ( subject instanceof Document ) {
137+ subject // $ExpectType Document
138+ } else if ( subject ) {
139+ subject // $ExpectType JQuery<HTMLElement>
140+ } else {
141+ subject // $ExpectType void
142+ }
143+ arg // $ExpectType string
144+ } )
145+ Cypress . Commands . add ( 'newCommand' , ( arg ) => {
88146 // $ExpectType string
89147 arg
90- return
148+ return cy . wrap ( new Promise < number > ( ( resolve ) => { resolve ( 5 ) } ) )
149+ } )
150+ Cypress . Commands . overwrite ( 'newCommand' , ( originalFn , arg ) => {
151+ arg // $ExpectType string
152+ originalFn // $ExpectedType Chainable['newCommand']
153+ originalFn ( arg ) // $ExpectType Chainable<number>
154+ } )
155+ Cypress . Commands . overwrite ( 'newCommand' , function ( originalFn , arg ) {
156+ this // $ExpectType Context
157+ arg // $ExpectType string
158+ originalFn // $ExpectedType Chainable['newCommand']
159+ originalFn . apply ( this , [ arg ] ) // $ExpectType Chainable<number>
160+ } )
161+ Cypress . Commands . overwrite < 'type' , 'element' > ( 'type' , ( originalFn , element , text , options ?: Partial < Cypress . TypeOptions & { sensitive : boolean } > ) => {
162+ element // $ExpectType JQuery<HTMLElement>
163+ text // $ExpectType string
164+
165+ if ( options && options . sensitive ) {
166+ // turn off original log
167+ options . log = false
168+ // create our own log with masked message
169+ Cypress . log ( {
170+ $el : element ,
171+ name : 'type' ,
172+ message : '*' . repeat ( text . length ) ,
173+ } )
174+ }
175+
176+ return originalFn ( element , text , options )
91177 } )
92178}
93179
0 commit comments