diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index f5ad85d34adb..380e89e3cace 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -107,6 +107,11 @@ declare namespace Cypress { fromAutWindow: WindowPosition & { x: number, y: number } } + /** + * Window type for Application Under Test(AUT) + */ + type AUTWindow = Window & typeof globalThis & ApplicationWindow + /** * The interface for user-defined properties in Window object under test. */ @@ -1043,7 +1048,7 @@ declare namespace Cypress { * * @see https://on.cypress.io/go */ - go(direction: HistoryDirection | number, options?: Partial): Chainable + go(direction: HistoryDirection | number, options?: Partial): Chainable /** * Get the current URL hash of the page that is currently active. @@ -1380,7 +1385,7 @@ declare namespace Cypress { * @example * cy.reload() */ - reload(options?: Partial): Chainable + reload(options?: Partial): Chainable /** * Reload the page without cache * @@ -1391,7 +1396,7 @@ declare namespace Cypress { * cy.visit('http://localhost:3000/admin') * cy.reload(true) */ - reload(forceReload: boolean): Chainable + reload(forceReload: boolean): Chainable /** * Make an HTTP GET request. @@ -1934,8 +1939,8 @@ declare namespace Cypress { * }) * */ - visit(url: string, options?: Partial): Chainable - visit(options: Partial & { url: string }): Chainable + visit(url: string, options?: Partial): Chainable + visit(options: Partial & { url: string }): Chainable /** * Wait for a number of milliseconds. @@ -2006,7 +2011,7 @@ declare namespace Cypress { }) ``` */ - window(options?: Partial): Chainable + window(options?: Partial): Chainable /** * Scopes all subsequent cy commands to within this element. @@ -2720,16 +2725,16 @@ declare namespace Cypress { /** * Called before your page has loaded all of its resources. * - * @param {Window} contentWindow the remote page's window object + * @param {AUTWindow} contentWindow the remote page's window object */ - onBeforeLoad(win: Window): void + onBeforeLoad(win: AUTWindow): void /** * Called once your page has fired its load event. * - * @param {Window} contentWindow the remote page's window object + * @param {AUTWindow} contentWindow the remote page's window object */ - onLoad(win: Window): void + onLoad(win: AUTWindow): void /** * Cypress will automatically apply the right authorization headers @@ -4637,12 +4642,12 @@ declare namespace Cypress { * 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. * @see https://on.cypress.io/catalog-of-events#App-Events */ - (action: 'window:before:load', fn: (win: Window) => void): void + (action: 'window:before:load', fn: (win: AUTWindow) => void): void /** * 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. * @see https://on.cypress.io/catalog-of-events#App-Events */ - (action: 'window:load', fn: (win: Window) => void): void + (action: 'window:load', fn: (win: AUTWindow) => void): void /** * 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. * @see https://on.cypress.io/catalog-of-events#App-Events diff --git a/cli/types/tests/actions.ts b/cli/types/tests/actions.ts index ae407691ce85..b022c1a8af6a 100644 --- a/cli/types/tests/actions.ts +++ b/cli/types/tests/actions.ts @@ -12,11 +12,11 @@ Cypress.on('window:alert', (text) => { }) Cypress.on('window:before:load', (win) => { - win // $ExpectType Window + win // $ExpectType AUTWindow }) Cypress.on('window:load', (win) => { - win // $ExpectType Window + win // $ExpectType AUTWindow }) Cypress.on('window:before:unload', (event) => { diff --git a/cli/types/tests/cypress-tests.ts b/cli/types/tests/cypress-tests.ts index ccc8e1cba734..75a5c01ba75a 100644 --- a/cli/types/tests/cypress-tests.ts +++ b/cli/types/tests/cypress-tests.ts @@ -287,6 +287,24 @@ cy subject // $ExpectType undefined }) +namespace CypressAUTWindowTests { + cy.go(2).then((win) => { + win // $ExpectType AUTWindow + }) + + cy.reload().then((win) => { + win // $ExpectType AUTWindow + }) + + cy.visit('https://google.com').then(win => { + win // $ExpectType AUTWindow + }) + + cy.window().then(win => { + win // $ExpectType AUTWindow + }) +} + namespace CypressOnTests { Cypress.on('uncaught:exception', (error, runnable) => { error // $ExpectType Error diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index 43ddf2062c13..85a1509d2dfc 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -144,7 +144,7 @@ namespace BlobTests { } cy.window().then(window => { - window // $ExpectType Window & typeof globalThis & ApplicationWindow + window // $ExpectType AUTWindow window.eval('1') })