When I use cy.intercept(), the API does not stub.
cy.intercept("GET", `${API}farm/list`, {
body: {
statusCode: 200,
message: "Request successful",
result: seededFarmList,
},
});
I am importing the fixture file like this:
import { seededFarmList } from '../../../../../fixtures/farm';
My API response looks like this:
{
"statusCode": 200,
"message": "Request successful",
"result": [
{ "id": 1 "farmName": "ABCD", },
{ "id": 2 "farmName": "EFGH", }
]
}
Any help would be appreciated.
I'm not entirely sure why it's not stubbing (presume you mean the server response is getting through?).
In any case, the stubbed response pattern is now a lot more complicated, and it's going to trip up a lot of people.
Here's my interpretation of the documentation,
In
cy.route(method, url, response), response documented as bodyIn
cy.intercept(method, url, routeHandler?), routeHandler is a more complicated beast.but object and StaticResponse are both objects - Cypress makes the distinction by looking at the object keys, according to this
StaticResponse keys are
Since you are sending statusCode, your object is a StaticResponse, and therefore message and result should be moved to body,
IMO they've over-engineered things a little - the fallback from StaticResponse to object (depending on keys) is a bit unnecessary.
I just found an example in the sample spec
network_requests.spec.js(added on Cypress 1st run).