[Cypress] Find Unstubbed Cypress Requests with Force 404

Requests that aren't stubbed will hit our real backend. To ensure we've stubbed all our routes, we can use the force404 method to send 404s from any unstubbed routes.

 

By force 404, we can do;

cy.server({ force404: true });

 

For example:

    cy.server({ force404: true });
    cy.get("[data-cy=todo-item-3] > .view > label").dblclick();
    cy.get(".edit")
      .clear()
      .type("update todo{enter}");

It will report 404 for PUT '/api/todos/3/' not found.

 

So mock it out:

  it("should update todo when dbclick", function() {
    cy.server({ force404: true });
    cy.route("PUT", "/api/todos/3", "ok").as("updated");
    cy.get("[data-cy=todo-item-3] > .view > label").dblclick();
    cy.get(".edit")
      .clear()
      .type("update todo{enter}");
    cy.wait("@updated");
  });

 

posted @ 2019-06-21 23:13  Zhentiw  阅读(350)  评论(0编辑  收藏  举报