https://cypress.io logo
Wait is it bad to have to specify the status code?...
# e2e-testing
w
Wait is it bad to have to specify the status code? When I've been doing stuff with failures I've wanted to specify the status code since that's part of what our app uses to decide what to do. Here's a tiny little helper we use at work:
Copy code
Cypress.Commands.add('interceptApi', (endpoint, fixturePath, statusCode = 200) => {
    cy.intercept(INTERCEPT_API_URL + endpoint, {
        statusCode,
        fixture: `/${fixturePath}.json`,
    }).as(fixturePath);
});
And we do stuff like
cy.interceptApi('/yourEndpoint', 'lil-fixture-path/500-error', 500);
then make our assertions.