cypress canceling an api request upon a form submit

Viewed 3786

Hello I have a form submit to a graph ql api. When I click the submit button I see that cypress cancels one of the requests to the api before it's able to get a response. Any idea how to prevent this? Edit: I've tried adding cy.wait(6000); or cy.wait('apiAlias'), post click submit, and neither help.

Text

1 Answers

Fixed this by preventing the default behavior of the form submit as suggested here

function preventFormSubmitDefault(selector) {
  cy.get(selector).then(form$ => {
    form$.on("submit", e => {
      e.preventDefault();
    });
  });
}

And then in the test:

    preventFormSubmitDefault("form");
    cy.get('[data-test="submitButton"]').click();
Related