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 body
Supply a response body to stub in the matching route.
In cy.intercept(method, url, routeHandler?), routeHandler is a more complicated beast.
routeHandler (string | object | Function | StaticResponse)
but object and StaticResponse are both objects - Cypress makes the distinction by looking at the object keys, according to this
If an object with no StaticResponse keys is passed, it will be sent as a JSON response body.
StaticResponse keys are
{
fixture?: string
body?: string | object | object[]
headers?: { [key: string]: string }
statusCode?: number
forceNetworkError?: boolean
delayMs?: number
throttleKbps?: number
}
Since you are sending statusCode, your object is a StaticResponse, and therefore message and result should be moved to body,
cy.intercept('GET',
`${API}farm/list`,
{
statusCode: 200,
body: {
message: 'Request successful',
result: seededFarmList
}
}
);
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).
beforeEach(() => {
cy.visit('https://example.cypress.io/commands/network-requests')
})
...
let message = 'whoa, this comment does not exist'
// Stub a response to PUT comments/ ****
cy.intercept({
method: 'PUT',
url: '**/comments/*',
}, {
statusCode: 404,
body: { error: message }, // stub returns above message
headers: { 'access-control-allow-origin': '*' },
delayMs: 500,
}).as('putComment')
// we have code that puts a comment when
// the button is clicked in scripts.js
cy.get('.network-put').click()
cy.wait('@putComment')
// our 404 statusCode logic in scripts.js executed
cy.get('.network-put-comment').should('contain', message)