mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-05 22:19:46 -06:00
fix: Update cy.press signature to be Chainable (#31698)
* Update cy.press signature to be Chainable Since it's added via `Commands.add`, I believe `cy.press` should have a return type of `Chainable<null>` rather than `void` * Update first_spec.cy.js Updated test for chainable * use addAll rather than add to avoid type check * fix unit test * Add cli entry * update changelog --------- Co-authored-by: Jennifer Shehane <shehane.jennifer@gmail.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
This commit is contained in:
@@ -9,8 +9,9 @@ _Released 5/20/2025 (PENDING)_
|
||||
|
||||
**Bugfixes:**
|
||||
|
||||
- Fixed an issue with the experimental usage of WebKit where Cypress incorrectly displayed `0` as the WebKit version. Addresses [#31684](https://github.com/cypress-io/cypress/issues/31684).
|
||||
- Fixed an issue where framebusting was occurring when `top.window.location` was being set explicitly. This fix does not require the `experimentalModifyObstructiveThirdPartyCode` configuration option. Addresses [#31687](https://github.com/cypress-io/cypress/issues/31687).
|
||||
- `cy.press()` now has a return type of `Chainable<null>` instead of `void` to match the convention of other commands that yield `null`. Addressed in [#31698](https://github.com/cypress-io/cypress/pull/31698).
|
||||
- Fixed an issue with the experimental usage of WebKit where Cypress incorrectly displayed `0` as the WebKit version. Addresses [#31684](https://github.com/cypress-io/cypress/issues/31684).
|
||||
|
||||
**Misc:**
|
||||
|
||||
|
||||
2
cli/types/cypress.d.ts
vendored
2
cli/types/cypress.d.ts
vendored
@@ -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>): void
|
||||
press(key: typeof Cypress.Keyboard.Keys[keyof typeof Cypress.Keyboard.Keys], options?: Partial<Loggable & Timeoutable>): Chainable<null>
|
||||
|
||||
/**
|
||||
* Get the immediately preceding sibling of each element in a set of the elements.
|
||||
|
||||
@@ -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
|
||||
return null
|
||||
}
|
||||
|
||||
if (Cypress.browser.family === 'webkit') {
|
||||
@@ -47,7 +47,7 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c
|
||||
},
|
||||
})
|
||||
|
||||
return
|
||||
return null
|
||||
}
|
||||
|
||||
if (Cypress.browser.name === 'firefox' && Number(Cypress.browser.majorVersion) < 135) {
|
||||
@@ -71,7 +71,11 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c
|
||||
} catch (err) {
|
||||
$errUtils.throwErr(err, { onFail: log })
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
return Commands.add('press', pressCommand)
|
||||
return Commands.addAll({
|
||||
press: pressCommand,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ describe('cy/commands/actions/press', () => {
|
||||
},
|
||||
}
|
||||
|
||||
// @ts-expect-error - this is a generic mock impl
|
||||
Commands = {
|
||||
add: vi.fn(),
|
||||
// @ts-expect-error - this is a generic mock impl
|
||||
addAll: vi.fn(),
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
@@ -84,14 +84,14 @@ describe('cy/commands/actions/press', () => {
|
||||
|
||||
addCommand(Commands, Cypress, cy, state, config)
|
||||
|
||||
expect(Commands.add).toHaveBeenCalledOnce()
|
||||
expect(Commands.addAll).toHaveBeenCalledOnce()
|
||||
|
||||
// @ts-expect-error
|
||||
const [[cmdName, cmd]]: [[string, PressCommand]] = Commands.add.mock.calls
|
||||
const [[obj]]: [[{press: PressCommand}]] = Commands.addAll.mock.calls
|
||||
|
||||
expect(cmdName).toEqual('press')
|
||||
expect(typeof obj.press).toBe('function')
|
||||
|
||||
press = cmd as PressCommand
|
||||
press = obj.press as PressCommand
|
||||
})
|
||||
|
||||
describe('with a valid key', () => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
describe('this one should pass', () => {
|
||||
it('dispatches a key press', () => {
|
||||
cy.press(Cypress.Keyboard.Keys.TAB)
|
||||
cy.press(Cypress.Keyboard.Keys.TAB).then((val) => {
|
||||
expect(val).to.be.null
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user