Skip to content

Commit 43f22c5

Browse files
committed
Test more APIs.
1 parent b8a76f2 commit 43f22c5

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

cli/types/cypress.d.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ declare namespace Cypress {
107107
fromAutWindow: WindowPosition & { x: number, y: number }
108108
}
109109

110+
/**
111+
* Window type for Application Under Test(AUT)
112+
*/
113+
type AUTWindow = Window & typeof globalThis & ApplicationWindow
114+
110115
/**
111116
* The interface for user-defined properties in Window object under test.
112117
*/
@@ -1043,7 +1048,7 @@ declare namespace Cypress {
10431048
*
10441049
* @see https://on.cypress.io/go
10451050
*/
1046-
go(direction: HistoryDirection | number, options?: Partial<Loggable & Timeoutable>): Chainable<Window>
1051+
go(direction: HistoryDirection | number, options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>
10471052

10481053
/**
10491054
* Get the current URL hash of the page that is currently active.
@@ -1380,7 +1385,7 @@ declare namespace Cypress {
13801385
* @example
13811386
* cy.reload()
13821387
*/
1383-
reload(options?: Partial<Loggable & Timeoutable>): Chainable<Window>
1388+
reload(options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>
13841389
/**
13851390
* Reload the page without cache
13861391
*
@@ -1391,7 +1396,7 @@ declare namespace Cypress {
13911396
* cy.visit('http://localhost:3000/admin')
13921397
* cy.reload(true)
13931398
*/
1394-
reload(forceReload: boolean): Chainable<Window>
1399+
reload(forceReload: boolean): Chainable<AUTWindow>
13951400

13961401
/**
13971402
* Make an HTTP GET request.
@@ -1934,8 +1939,8 @@ declare namespace Cypress {
19341939
* })
19351940
*
19361941
*/
1937-
visit(url: string, options?: Partial<VisitOptions>): Chainable<Window>
1938-
visit(options: Partial<VisitOptions> & { url: string }): Chainable<Window>
1942+
visit(url: string, options?: Partial<VisitOptions>): Chainable<AUTWindow>
1943+
visit(options: Partial<VisitOptions> & { url: string }): Chainable<AUTWindow>
19391944

19401945
/**
19411946
* Wait for a number of milliseconds.
@@ -2006,7 +2011,7 @@ declare namespace Cypress {
20062011
})
20072012
```
20082013
*/
2009-
window(options?: Partial<Loggable & Timeoutable>): Chainable<Window & typeof globalThis & ApplicationWindow>
2014+
window(options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>
20102015

20112016
/**
20122017
* Scopes all subsequent cy commands to within this element.
@@ -2720,16 +2725,16 @@ declare namespace Cypress {
27202725
/**
27212726
* Called before your page has loaded all of its resources.
27222727
*
2723-
* @param {Window} contentWindow the remote page's window object
2728+
* @param {AUTWindow} contentWindow the remote page's window object
27242729
*/
2725-
onBeforeLoad(win: Window): void
2730+
onBeforeLoad(win: AUTWindow): void
27262731

27272732
/**
27282733
* Called once your page has fired its load event.
27292734
*
2730-
* @param {Window} contentWindow the remote page's window object
2735+
* @param {AUTWindow} contentWindow the remote page's window object
27312736
*/
2732-
onLoad(win: Window): void
2737+
onLoad(win: AUTWindow): void
27332738

27342739
/**
27352740
* Cypress will automatically apply the right authorization headers
@@ -4637,12 +4642,12 @@ declare namespace Cypress {
46374642
* Fires as the page begins to load, but before any of your applications JavaScript has executed. This fires at the exact same time as `cy.visit()` `onBeforeLoad` callback. Useful to modify the window on a page transition.
46384643
* @see https://on.cypress.io/catalog-of-events#App-Events
46394644
*/
4640-
(action: 'window:before:load', fn: (win: Window) => void): void
4645+
(action: 'window:before:load', fn: (win: AUTWindow) => void): void
46414646
/**
46424647
* Fires after all your resources have finished loading after a page transition. This fires at the exact same time as a `cy.visit()` `onLoad` callback.
46434648
* @see https://on.cypress.io/catalog-of-events#App-Events
46444649
*/
4645-
(action: 'window:load', fn: (win: Window) => void): void
4650+
(action: 'window:load', fn: (win: AUTWindow) => void): void
46464651
/**
46474652
* Fires when your application is about to navigate away. The real event object is provided to you. Your app may have set a `returnValue` on the event, which is useful to assert on.
46484653
* @see https://on.cypress.io/catalog-of-events#App-Events

cli/types/tests/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Cypress.on('window:alert', (text) => {
1212
})
1313

1414
Cypress.on('window:before:load', (win) => {
15-
win // $ExpectType Window
15+
win // $ExpectType AUTWindow
1616
})
1717

1818
Cypress.on('window:load', (win) => {
19-
win // $ExpectType Window
19+
win // $ExpectType AUTWindow
2020
})
2121

2222
Cypress.on('window:before:unload', (event) => {

cli/types/tests/cypress-tests.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ cy
287287
subject // $ExpectType undefined
288288
})
289289

290+
namespace CypressAUTWindowTests {
291+
cy.go(2).then((win) => {
292+
win // $ExpectType AUTWindow
293+
})
294+
295+
cy.reload().then((win) => {
296+
win // $ExpectType AUTWindow
297+
})
298+
299+
cy.visit('https://google.com').then(win => {
300+
win // $ExpectType AUTWindow
301+
})
302+
303+
cy.window().then(win => {
304+
win // $ExpectType AUTWindow
305+
})
306+
}
307+
290308
namespace CypressOnTests {
291309
Cypress.on('uncaught:exception', (error, runnable) => {
292310
error // $ExpectType Error

cli/types/tests/kitchen-sink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace BlobTests {
144144
}
145145

146146
cy.window().then(window => {
147-
window // $ExpectType Window & typeof globalThis & ApplicationWindow
147+
window // $ExpectType AUTWindow
148148

149149
window.eval('1')
150150
})

0 commit comments

Comments
 (0)