Skip to content

Instantly share code, notes, and snippets.

@adamdehaven
Created January 21, 2022 23:08
Show Gist options
  • Save adamdehaven/aba81d5951c931c44260212e98c69bde to your computer and use it in GitHub Desktop.
Save adamdehaven/aba81d5951c931c44260212e98c69bde to your computer and use it in GitHub Desktop.
cy.get('.button').click().then(() => {
cy.wrap(Cypress.vueWrapper.emitted()).should('have.property', 'click-forgot-password-link')
})
@adamdehaven
Copy link
Author

How would you access the emitted event (and it’s payload) instead?

@lmiller1990
Copy link

lmiller1990 commented Jan 25, 2022

Vuetify's next branch has a bunch of Cypress component testing examples. Button. They use TSX but you can do something like this:

const onRegister = cy.stub()

mount(KongAuthRegister, {
  props: { 
    onRegisterSuccess: onRegister
  }
})

cy.intercept('POST', '**/register', {
  body: {
    organizationID: '187e2b65-ec69-421c-a7ba-3e946c4e5077',
  },
}).as('register-request')

// stuff ...

cy.wait('@register-request').its('response.body').should('have.property', 'organizationID').then(() => {
  // Check for emitted event
  expect(onRegister).to.have.been.calledWith(......) // <================== your object here??
})

The trick is Vue turns @register-success into an onRegisterSuccess props when it compiles.

@lmiller1990
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment