https://cypress.io logo
Join Discord
Powered by
# general-chat
  • g

    gray-kilobyte-89541

    06/27/2022, 4:27 PM
    no, maybe take a Cypress workshop to see many practices in action, here is 100% open source one https://github.com/bahmutov/cypress-workshop-basics
  • s

    silly-journalist-41771

    06/27/2022, 7:02 PM
    what's wrong with this
  • s

    silly-journalist-41771

    06/27/2022, 7:02 PM
    this is spec file
  • s

    silly-journalist-41771

    06/27/2022, 7:02 PM
    trying to use custom command to pass through randomly generate user data from chance,js
  • s

    silly-journalist-41771

    06/27/2022, 7:03 PM
    this is the error
  • l

    late-planet-4481

    06/27/2022, 7:19 PM
    Can you paste the definition of the
    checkout
    class? That's surely where your problem lies. I might not be much help myself (I know how to chain custom
    cy
    commands, but I fumble through js promises), but I bet someone else would be able to spot the issue.
  • s

    silly-journalist-41771

    06/27/2022, 7:20 PM
    I removed prevsubject
  • s

    silly-journalist-41771

    06/27/2022, 7:20 PM
    and subject argument
  • s

    silly-journalist-41771

    06/27/2022, 7:20 PM
    and cy.wrap(subject)
  • s

    silly-journalist-41771

    06/27/2022, 7:20 PM
    and it worked
  • l

    late-planet-4481

    06/27/2022, 7:21 PM
    All's well that ends well 🙂
  • s

    silly-journalist-41771

    06/27/2022, 7:21 PM
    yh I'm trying to figure out when to use prevsubject
  • s

    silly-journalist-41771

    06/27/2022, 7:21 PM
    and cy.wrap
  • s

    silly-journalist-41771

    06/27/2022, 7:21 PM
    wrap just allows me to chain a cypress command right
  • s

    silly-journalist-41771

    06/27/2022, 7:21 PM
    to a parent
  • s

    silly-journalist-41771

    06/27/2022, 7:22 PM
    function
  • l

    late-planet-4481

    06/27/2022, 7:22 PM
    The way it works: the subject of the last
    cy
    command you ran is what is yielded by your custom command. So that can be
    cy.wrap()
    or can even be
    cy.get()
    . It's whatever you invoked last.
  • s

    silly-journalist-41771

    06/27/2022, 7:24 PM
    so someone helped me make this custom command
  • s

    silly-journalist-41771

    06/27/2022, 7:24 PM
    how does it work
  • s

    silly-journalist-41771

    06/27/2022, 7:24 PM
    it lets me chain on click and wait in my spec file
  • s

    silly-journalist-41771

    06/27/2022, 7:25 PM
    but what is the cy.wrap doing here
  • s

    silly-journalist-41771

    06/27/2022, 7:25 PM
    do I need it?
  • l

    late-planet-4481

    06/27/2022, 7:25 PM
    prevSubject: true
    is what makes your command chainable. It means it will accept the yield of the previous command in place of the first argument in the list. In this case that's
    subject
    .
  • s

    silly-journalist-41771

    06/27/2022, 7:26 PM
    and what is the yield of the previous command in this example
  • l

    late-planet-4481

    06/27/2022, 7:27 PM
    cy.wrap()
    might not be necessary. It depends on what was yielded. If it yielded a cypress object then you don't need
    cy.wrap()
    .
    cy.wrap()
    would be needed if something agnostic like a string were passed in.
  • l

    late-planet-4481

    06/27/2022, 7:27 PM
    That's a good question. Without seeing the previous command's definition I don't know what the yield would be.
  • s

    silly-journalist-41771

    06/27/2022, 7:27 PM
    well this is the function
  • s

    silly-journalist-41771

    06/27/2022, 7:28 PM
    sorry this
  • s

    silly-journalist-41771

    06/27/2022, 7:28 PM
    it's a cy.get
  • s

    silly-journalist-41771

    06/27/2022, 7:28 PM
    getting the locator
1...585960...127Latest