cypress canceling an api request upon a form submit

半城伤御伤魂 提交于 2021-01-03 06:44:25

问题


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:


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();


来源:https://stackoverflow.com/questions/60385480/cypress-canceling-an-api-request-upon-a-form-submit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!