Skip to content

Commit

Permalink
Test more APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Jun 30, 2020
1 parent b8a76f2 commit 43f22c5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
29 changes: 17 additions & 12 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -1043,7 +1048,7 @@ declare namespace Cypress {
*
* @see https://on.cypress.io/go
*/
go(direction: HistoryDirection | number, options?: Partial<Loggable & Timeoutable>): Chainable<Window>
go(direction: HistoryDirection | number, options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>

/**
* Get the current URL hash of the page that is currently active.
Expand Down Expand Up @@ -1380,7 +1385,7 @@ declare namespace Cypress {
* @example
* cy.reload()
*/
reload(options?: Partial<Loggable & Timeoutable>): Chainable<Window>
reload(options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>
/**
* Reload the page without cache
*
Expand All @@ -1391,7 +1396,7 @@ declare namespace Cypress {
* cy.visit('http://localhost:3000/admin')
* cy.reload(true)
*/
reload(forceReload: boolean): Chainable<Window>
reload(forceReload: boolean): Chainable<AUTWindow>

/**
* Make an HTTP GET request.
Expand Down Expand Up @@ -1934,8 +1939,8 @@ declare namespace Cypress {
* })
*
*/
visit(url: string, options?: Partial<VisitOptions>): Chainable<Window>
visit(options: Partial<VisitOptions> & { url: string }): Chainable<Window>
visit(url: string, options?: Partial<VisitOptions>): Chainable<AUTWindow>
visit(options: Partial<VisitOptions> & { url: string }): Chainable<AUTWindow>

/**
* Wait for a number of milliseconds.
Expand Down Expand Up @@ -2006,7 +2011,7 @@ declare namespace Cypress {
})
```
*/
window(options?: Partial<Loggable & Timeoutable>): Chainable<Window & typeof globalThis & ApplicationWindow>
window(options?: Partial<Loggable & Timeoutable>): Chainable<AUTWindow>

/**
* Scopes all subsequent cy commands to within this element.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cli/types/tests/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
18 changes: 18 additions & 0 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/types/tests/kitchen-sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace BlobTests {
}

cy.window().then(window => {
window // $ExpectType Window & typeof globalThis & ApplicationWindow
window // $ExpectType AUTWindow

window.eval('1')
})

0 comments on commit 43f22c5

Please sign in to comment.