Akshay Vijay Jain
Akshay Vijay Jain

Reputation: 15945

Can we read and assert on response in cypress cy.route Function?

I couldn't find anything in the documentation about asserting on the xhr response on the page.
Would like to know how it could be achieved in code?

Upvotes: 0

Views: 378

Answers (1)

Hatem Hatamleh
Hatem Hatamleh

Reputation: 76

you can use expect let's suppose that you set up the cypress server as below:

cy.server()
cy.route({<your route details>}).as('aliasName')

Then later in the code, you can use

cy.wait('@aliasName').then(xhr => {
  expect(xhr.responseBody.<your Item>).to.eql('something')
})

Upvotes: 1

Related Questions