Context:
I now need to start implementing E2E tests for a webapp that uses a "complicated" api. So for testing one site I need to intercept about 15 REST requests. That API is obviously not well designed, but I can't change it because it is from a third party and my webapp relies on that.
Questions:
How should I handle the
cy.intercept()calls? Because just for one test it quickly becomes hard to read what actually happens, because the interception of the requests takes 50 lines of code.Should I keep the
cy.intercept()calls in my test file or should I outsource them like this:
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
});
});