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

Cannot hook from previous subject on the child custom command #38

Open
fahdilahady opened this issue Feb 28, 2024 · 1 comment
Open

Comments

@fahdilahady
Copy link

fahdilahady commented Feb 28, 2024

Cypress.Commands.add('deepClick', { prevSubject: true }, (subject: Cypress.Chainable<any>) => {
  const click = ($el) => $el.click();
  subject.pipe(click).should(($el) => expect($el).to.not.visible);
  return subject;
});

above child custom command will return pipe is not a function.

it's also doesn't works well if we hook it from .find()

so currently I used as parent custom command as below

Cypress.Commands.add('deepClick', (selector: string, ...args) => {
  const click = ($el) => $el.click();
  return cy.get(selector, ...args).pipe(click).should(($el) => expect($el).to.not.visible);
});

which the usage is become like this:
cy.deepClick('button[data-cy="SendToUnderwriting"]')

instead of
cy.get('button[data-cy="SendToUnderwriting"]').deepClick();

@fahdilahady fahdilahady changed the title Cannot hook from previous subject on the custom command Cannot hook from previous subject on the child custom command Feb 28, 2024
@NicholasBoll
Copy link
Owner

subject is not a Cypress.Chainable, it is a JQuery. pipe exists on the chainable, not the jQuery wrapper.

You'll have to do cy.wrap(subject).pipe(... inside the deepClick custom function. Then you can do cy.get(...).deepClick()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants