Scenario:
Currently, the task at hand involves setting up end-to-end tests for a web application that relies on a rather complex API. In order to test just one aspect of the site, approximately 15 REST requests need to be intercepted. The API in question is not particularly well-designed, but due to it being a third-party integration critical to the functioning of the web app, making changes to it is not feasible.
Queries:
What would be the best approach for managing the
cy.intercept()
calls? With each test requiring such extensive interception setup, readability becomes an issue as the code can quickly span over 50 lines.Is it advisable to keep the
cy.intercept()
calls within the test file or should they be outsourced into separate files like below:
fixtures/car-list.ts
export function mockCarList() {
cy.intercept()
cy.intercept()
...
}
integration/car-list.spec.ts
import { mockCarList } from '../fixtures/car-list'
describe('Test car', () => {
it('Should test car list', () => {
mockCarList();
do test stuff
});
});