I wish to create a custom command that contains status code assertions:
cy.wait('@interceptedEndpoint')
.its('response.statusCode')
.should('eq', 200)
the last two lines are what I want inside the custom command
.its('response.statusCode')
.should('eq', 200)
My initial idea is below which obviously wouldn't work
Cypress.commands.add('checkResponse', {prevSubject: 'element'}, () => {
.its('response.statusCode')
.should('eq', 200)
})
What am I missing above to make the custom command creation correct?
EDIT: In addition to Udo.Kier's answer. I needed to set prevSubject
to true to make it accept the response for the expected assertion.