Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cypress should be called with value test

Looking for a test like below. Basically I get it to work using cy.get('@myLog').should('be.called') but I’m trying to test the value console log is using when called. In jest it would be toHaveBeenCalledWith() so the equivalent in cypress is what I’m after ?

   cy.window().then((win) => {
      cy.wrap(cy.spy(win.console, 'log')).as('myLog')
    })
 
    cy.get('@myLog')
      .should('be.called')
      .and('have.value', 'clicked')

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

cy.spy() and cy.stub() you can use Sinon-chai assertions. So for you instance you may want to use be.calledWith.

cy.window().then((win) => {
  cy.wrap(cy.spy(win.console, 'log')).as('myLog')
})
 
cy.get('@myLog')
  .should('be.calledWith', 'clicked')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading