callback hell
# i-need-help
i
Any better way to avoid callback hell for .then ?
Copy code
let count = {
  interest: 0,
};

cy.fixture('campaign_interest.json').then((mockAPIInterest) => {
  cy.fixture('campaign_interest_empty.json').then((mockEmptyAPIInterest) => {
    cy.intercept('GET', '/api/v2/dmp-light/campaign/interest/default*', (req) => {
      count.interest++;
      if (count.interest <= 1) {
        req.reply({
          statusCode: 200,
          body: [mockAPIInterest]
        });
      } else {
        req.reply({
          statusCode: 200,
          body: [mockEmptyAPIInterest],
        });
      }
    }).as('getInterest');
  });
});
g
Yes, you can preload fixtures and use aliases and you can use “times” option with cy intercept to reply only several times. For more see my paid course https://cypress.tips/courses/network-testing