-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Cannot overwrite get
command
#7267
Comments
You would basically need to reimplement what Cypress does in our own command definitions if you want to overwrite the Overwrite should always return the originalFn, so you can't chain something off of it like In this situation I would recommend just creating a new custom command for this usage since you would need to use Cypress.Commands.add("getVisible", (selector, options) => {
return cy.get(selector).should('be.visible')
});
it("get overwrite", () => {
cy.visit("https://example.cypress.io/commands/actions");
cy.getVisible(".action-email")
}) |
Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen. |
@jennifer-shehane Apologies for the delay in replying. Just for my education, is
somewhere in the docs? If not, would you be open to explaining why that's the case? I'd also be happy to send an MR for a docs update once I do understand. Thanks so much! |
Situation: There are some things we would almost always want to assert on the elements we find, most notably that the element(s) is visible and the number that we find is what we expect (defaulting to 1). I want to add this behavior to the default
get
command rather than creating a separate command, so more junior developers don't end up using the wrong one and then miss the default assertions.Current behavior:
Unable to overwrite
get
command. In case it's unclear, I created a minimal repro repo, and this file in it has the two different things I tried:Desired behavior:
Cypress allows me to overwrite
get
, or at least gives me a more informative error message about why that isn't supportedTest code to reproduce
https://github.com/ncknuna/cypress-no-get-overwrite
Versions
Cypress version 4.5.0
Mac OS X v 10.15.4
Chrome Version 80.0.3987.163
The text was updated successfully, but these errors were encountered: