Is there any way to write a test case to expect cy.request
to fail(non-2** response) on certain params?
I attempted to use the following snippet:
it('intentionally fails', () => {
expect(
() => {
cy.request({
method: 'POST',
url: `https://valid.url/api/items`,
body: {name: "foo"},
})
}
).to.throw('bar')
})
but it fails with:
AssertionError
expected [Function] to throw an error
This is API-only project, so basically I only use cy.request
everywhere.
Without the expect
function block it fails with:
CypressError
cy.request() failed on
The response we received from your web server was:
> 500: Internal Server Error