Skip to content

yield void/undefined from cy.press, make better use of the command interface definition #31707

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ declare namespace Cypress {
* cy.press(Cypress.Keyboard.Keys.TAB) // dispatches a keydown and press event to the browser, followed by a keyup event.
* @see https://on.cypress.io/press
*/
press(key: typeof Cypress.Keyboard.Keys[keyof typeof Cypress.Keyboard.Keys], options?: Partial<Loggable & Timeoutable>): Chainable<null>
press(key: typeof Cypress.Keyboard.Keys[keyof typeof Cypress.Keyboard.Keys], options?: Partial<Loggable & Timeoutable>): Chainable<void>

/**
* Get the immediately preceding sibling of each element in a set of the elements.
Expand Down
12 changes: 6 additions & 6 deletions packages/driver/src/cy/commands/actions/press.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import $errUtils from '../../../cypress/error_utils'
import $utils from '../../../cypress/utils'

export interface PressCommand {
(key: KeyPressSupportedKeys, userOptions?: Partial<Cypress.Loggable> & Partial<Cypress.Timeoutable>): void
(key: KeyPressSupportedKeys, userOptions?: Partial<Cypress.Loggable> & Partial<Cypress.Timeoutable>): Promise<void>
}

export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, cy: $Cy, state: StateFunc, config: any) {
async function pressCommand (key: KeyPressSupportedKeys, userOptions?: Partial<Cypress.Loggable> & Partial<Cypress.Timeoutable>) {
const press: PressCommand = async function pressCommand (key: KeyPressSupportedKeys, userOptions?: Partial<Cypress.Loggable> & Partial<Cypress.Timeoutable>) {
const options: Cypress.Loggable & Partial<Cypress.Timeoutable> = defaults({}, userOptions, {
log: true,
})
Expand All @@ -36,7 +36,7 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c

// throwErrByPath always throws, but there's no way to indicate that
// code beyond this point is unreachable to typescript / linters
return null
return
}

if (Cypress.browser.family === 'webkit') {
Expand All @@ -47,7 +47,7 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c
},
})

return null
return
}

if (Cypress.browser.name === 'firefox' && Number(Cypress.browser.majorVersion) < 135) {
Expand All @@ -72,10 +72,10 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c
$errUtils.throwErr(err, { onFail: log })
}

return null
return
}

return Commands.addAll({
press: pressCommand,
press,
})
}
Loading