Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adding overload to screenshot to fix type errors when overwriting this command. #27130

Merged
merged 13 commits into from
Jul 7, 2023
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 12.17.1

_Released 07/18/2023 (PENDING)_

**Bugfixes:**

- Fixed an issue with the Typescript types of [`cy.screenshot()`](https://docs.cypress.io/api/commands/screenshot). Fixed in [#27130](https://github.com/cypress-io/cypress/pull/27130).

## 12.17.0

_Released 07/05/2023_
Expand Down
6 changes: 4 additions & 2 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1901,15 +1901,17 @@ declare namespace Cypress {
* cy.screenshot()
* cy.get(".post").screenshot()
*/
screenshot(options?: Partial<Loggable & Timeoutable & ScreenshotOptions>): Chainable<null>
screenshot(options?: Partial<Loggable & Timeoutable & ScreenshotOptions>): Chainable<Subject>

/**
* Take a screenshot of the application under test and the Cypress Command Log and save under given filename.
*
* @see https://on.cypress.io/screenshot
* @example
* cy.screenshot("post-element")
* cy.get(".post").screenshot("post-element")
*/
screenshot(fileName: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions>): Chainable<null>
screenshot(fileName: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions>): Chainable<Subject>

/**
* Scroll an element into view.
Expand Down
12 changes: 12 additions & 0 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ namespace CypressCommandsTests {

return originalFn(element, text, options)
})
Cypress.Commands.overwrite<'screenshot', 'element'>('screenshot', (originalFn, subject, fileName, options) => {
subject // $ExpectType JQueryWithSelector<HTMLElement>
fileName // $ExpectType string
options // $ExpectType Partial<Loggable & Timeoutable & ScreenshotOptions> | undefined
})

Cypress.Commands.addQuery('newQuery', function(arg) {
this // $ExpectType Command
Expand Down Expand Up @@ -661,6 +666,9 @@ namespace CypressFilterTests {
}

namespace CypressScreenshotTests {
cy.screenshot().then((result) => {
result // $ExpectType undefined
})
cy.screenshot('example-name')
cy.screenshot('example', { log: false })
cy.screenshot({ log: false })
Expand All @@ -672,6 +680,10 @@ namespace CypressScreenshotTests {
log: true,
blackout: []
})
cy.get<HTMLDivElement>('#id').screenshot('example-name', { log: false })
cy.get<HTMLDivElement>('#id').screenshot().then((result) => {
result // $ExpectType JQuery<HTMLDivElement>
})
}

namespace CypressShadowDomTests {
Expand Down