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

Cypress.Commands.add with object argument #18886

Closed
benwiley4000 opened this issue Nov 11, 2021 · 3 comments · Fixed by #20894
Closed

Cypress.Commands.add with object argument #18886

benwiley4000 opened this issue Nov 11, 2021 · 3 comments · Fixed by #20894

Comments

@benwiley4000
Copy link

What would you like?

I want to be able to do this:

Cypress.Commands.add({
  myCommand(arg) {
    // ...
  },
  myOtherCommand(arg) {
    // ...
  }
});

Why is this needed?

This way we can maintain a commands.js file that looks like this:

export function myCommand(arg) {
  // ...
}

export function myOtherCommand(arg) {
  // ...
}

And we can add them all like this:

import * as commands from './commands';
Cypress.Commands.add(commands);

Other

This will be especially useful for typescript where declaring the function separately from the Cypress.Commands.add(...) call is helpful for maintaining correct typing in Cypress.Chainable.

@BlueWinds
Copy link
Contributor

We already have addAll available and use it inside Cypress. For example: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/files.ts. Does Cypress.Commands.addAll() work for what you're trying to do?

This isn't documented anywhere at the moment - but if someone wanted to open a PR to add it to the docs, that would be very welcome.

@cypress-bot cypress-bot bot added the stage: needs review The PR code is done & tested, needs review label Apr 4, 2022
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Apr 11, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 11, 2022

The code for this is done in cypress-io/cypress#20894, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 11, 2022

Released in 9.5.4.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.5.4, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants