In this video, I show how to use cy.visit and cy.request commands to verify the server is returning a 404 page for invalid resource URLs. Find the full source code in https://github.com/bahmutov/cypress-c... In summary, I did:
const url = '/does-not-exist'
cy.request({ url, failOnStatusCode: false })
.its('status', { timeout: 0 })
.should('equal', 404)
cy.visit(url, { failOnStatusCode: false })
cy.contains('span', '404')