I’m trying in cypress tests to check that the API call is only made once.
Then I try to keep making changes, and I wanted to verify that the calls aren’t actually being made.
<code> it("update statement from the map is edited and sent only once", () => {
cy.intercept("POST", mapsPath, { fixture: "initDefaultMap.json" }).as("saveMap");
cy.intercept("POST", lrsPath, { fixture: "statementOpened.json" }).as("statementUpdatedMap");
cy.get('[data-cy="canvas"]').click();
cy.get("zt-color-picker[icon='bg-color']").shadow().find("zt-button").shadow().find(".zt-button").click();
cy.get("zt-color-picker[icon='bg-color']")
.shadow()
.find("#color-picker-submenu > ul > li.color-boxes[data-color='#99FFCC']")
.click();
cy.wait("@statementUpdatedMap").then((evt) => expect(extractVerb(evt)).to.be.equal("updated"));
cy.wait("@saveMap");
cy.intercept("POST", lrsPath, cy.spy());
cy.get('[data-cy="edit-title"]').click();
cy.get("body [data-cy='input-title'] input").clear().type("mappa bella");
cy.get('[data-cy="canvas"]').click();
cy.wait(1000).then(() => expect(cy.spy()).not.to.be.called);
cy.get("zt-color-picker[icon='bg-color']").shadow().find("zt-button").shadow().find(".zt-button").click();
cy.get("zt-color-picker[icon='bg-color']")
.shadow()
.find("#color-picker-submenu > ul > li.color-boxes[data-color='#5533FF']")
.click();
cy.wait(1000).then(() => expect(cy.spy()).not.to.be.called);
});
</code>
<code> it("update statement from the map is edited and sent only once", () => {
cy.intercept("POST", mapsPath, { fixture: "initDefaultMap.json" }).as("saveMap");
cy.intercept("POST", lrsPath, { fixture: "statementOpened.json" }).as("statementUpdatedMap");
cy.get('[data-cy="canvas"]').click();
cy.get("zt-color-picker[icon='bg-color']").shadow().find("zt-button").shadow().find(".zt-button").click();
cy.get("zt-color-picker[icon='bg-color']")
.shadow()
.find("#color-picker-submenu > ul > li.color-boxes[data-color='#99FFCC']")
.click();
cy.wait("@statementUpdatedMap").then((evt) => expect(extractVerb(evt)).to.be.equal("updated"));
cy.wait("@saveMap");
cy.intercept("POST", lrsPath, cy.spy());
cy.get('[data-cy="edit-title"]').click();
cy.get("body [data-cy='input-title'] input").clear().type("mappa bella");
cy.get('[data-cy="canvas"]').click();
cy.wait(1000).then(() => expect(cy.spy()).not.to.be.called);
cy.get("zt-color-picker[icon='bg-color']").shadow().find("zt-button").shadow().find(".zt-button").click();
cy.get("zt-color-picker[icon='bg-color']")
.shadow()
.find("#color-picker-submenu > ul > li.color-boxes[data-color='#5533FF']")
.click();
cy.wait(1000).then(() => expect(cy.spy()).not.to.be.called);
});
</code>
it("update statement from the map is edited and sent only once", () => {
cy.intercept("POST", mapsPath, { fixture: "initDefaultMap.json" }).as("saveMap");
cy.intercept("POST", lrsPath, { fixture: "statementOpened.json" }).as("statementUpdatedMap");
cy.get('[data-cy="canvas"]').click();
cy.get("zt-color-picker[icon='bg-color']").shadow().find("zt-button").shadow().find(".zt-button").click();
cy.get("zt-color-picker[icon='bg-color']")
.shadow()
.find("#color-picker-submenu > ul > li.color-boxes[data-color='#99FFCC']")
.click();
cy.wait("@statementUpdatedMap").then((evt) => expect(extractVerb(evt)).to.be.equal("updated"));
cy.wait("@saveMap");
cy.intercept("POST", lrsPath, cy.spy());
cy.get('[data-cy="edit-title"]').click();
cy.get("body [data-cy='input-title'] input").clear().type("mappa bella");
cy.get('[data-cy="canvas"]').click();
cy.wait(1000).then(() => expect(cy.spy()).not.to.be.called);
cy.get("zt-color-picker[icon='bg-color']").shadow().find("zt-button").shadow().find(".zt-button").click();
cy.get("zt-color-picker[icon='bg-color']")
.shadow()
.find("#color-picker-submenu > ul > li.color-boxes[data-color='#5533FF']")
.click();
cy.wait(1000).then(() => expect(cy.spy()).not.to.be.called);
});
I tried using cy.spy(), but it didn’t work
New contributor
Oleksandr Oleksyuk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.