limited-barista-33480
10/26/2022, 10:29 PMtall-forest-29063
10/26/2022, 11:03 PMgray-kilobyte-89541
10/26/2022, 11:10 PMmysterious-pilot-21916
10/27/2022, 7:34 AMfresh-doctor-14925
10/27/2022, 7:48 AMrecord
flagaloof-rocket-79742
10/27/2022, 9:58 AMaloof-rocket-79742
10/27/2022, 10:02 AMincalculable-nightfall-21641
10/27/2022, 10:17 AMfresh-doctor-14925
10/27/2022, 12:06 PMfresh-doctor-14925
10/27/2022, 12:12 PMsrc
, you can then import the components you needaloof-rocket-79742
10/27/2022, 12:12 PMincalculable-nightfall-21641
10/27/2022, 12:16 PMfuture-baker-50174
10/27/2022, 12:17 PMjs
cy.intercept("POST", "/api/something", (req) => {
req.on("before:response", () => {
cy.get("#message").should("equal", "Request sent");
});
req.on("after:response", () => {
cy.get("#message").should("equal", "Response received");
});
req.continue();
});
But what can I do instead?fresh-doctor-14925
10/27/2022, 12:21 PMcy.intercept("POST","/api/something").as('apiSomething')
...
cy.wait('@apiSomething')
.its('response.status')
.should('be', 200)
future-baker-50174
10/27/2022, 12:21 PMfresh-doctor-14925
10/27/2022, 12:23 PMfresh-doctor-14925
10/27/2022, 12:28 PMintercept()
is intended to do. I suggest you have something like this in your test body:
// Or whatever action you're doing
cy.get('#submit').click()
cy.get("#message").should("equal", "Request sent");
cy.wait('@apiSomething');
cy.get("#message").should("equal", "Request received");
thankful-pencil-94627
10/27/2022, 12:39 PMshould('be.visible');
to avoid static waitsthankful-pencil-94627
10/27/2022, 12:40 PMcy.get('.search-button).should('have.length',number)
or just a show('be.visible')
to wait until appearfuture-baker-50174
10/27/2022, 1:28 PMfresh-doctor-14925
10/27/2022, 1:59 PMwait()
that is holding you up here because the call resolves too quickly you could instead spy on the intercept and then assert there's been a successful call
cy.intercept('/some/endpoint', cy.spy().as('someEndpoint'))
...
cy.click()
cy.contains('#message', 'Request sent')
cy.contains('#message', 'Request received')
cy.get("@fruitEndpoint")
.should('have.been.calledOnce')
early-article-61542
10/27/2022, 2:13 PMstale-optician-85950
10/27/2022, 2:54 PMdata-testid
is to be unique, to allow the creation of strong integration tests.
Documented here https://docs.cypress.io/guides/references/best-practices#Selecting-Elementsacceptable-fall-11897
10/27/2022, 4:19 PMadorable-smartphone-87280
10/27/2022, 4:56 PMmysterious-belgium-25713
10/27/2022, 4:58 PMcareful-toothbrush-49639
10/27/2022, 5:47 PMcareful-toothbrush-49639
10/27/2022, 6:20 PMcareful-toothbrush-49639
10/27/2022, 6:20 PMstale-optician-85950
10/27/2022, 6:53 PM.eq()
index https://docs.cypress.io/api/commands/eq