How to add before:spec hook in cypress cucumber framework

Viewed 13
 getListOfPlans() {
    return new Cypress.Promise((resolve) => {
      usersUtil.getCurrentCompany().then((company) => {
        cy.request({
          method: 'GET',
          url: `${TrainingPlanApi.baseTrainingPlanApiUrl}/company/${company.id}/plan`,
        }).then((resp) => {
          expect(resp.status).to.eq(200);
          cy.wrap(resp.body.data).as('existingTrainingPlans');
          resolve(resp.body.data);
        });
      });
      if (this.environment === 'local') {
        trainingTrainingPlanListPage.visit();
      } else {
        mainMenu.openTrainingPlans();
        trainingPlanApi.getListOfPlans().then((data) => {
          cy.get(`@existingTrainingPlans`).each((planData) => {
            const plan = planData as unknown as TrainingPlan;
            trainingPlanApi.delete(plan.ksuid);
          });
        });
      }
    }) as unknown as Chainable<TrainingPlanRequest>;

i need to call the above api function in the before:spec

on('before:spec', async (spec) => {
    getListOfPlans
  });

but the above doesnt work, not sure how to solve this please

0 Answers
Related