我们可以在 cypress cy.route 函数中读取和断言响应吗?



我在文档中找不到有关在页面上断言 xhr 响应的任何内容。
想知道如何在代码中实现它吗?

你可以使用expect。 假设您按如下方式设置了赛普拉斯服务器:

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

然后稍后在代码中,您可以使用

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

最新更新