magnificent-lamp-25446
01/10/2022, 6:06 PMwonderful-match-15836
01/10/2022, 6:22 PMcy.visit
and both assertions all in the same it
block, with no before
.
If I wanted to keep them isolated like you have them, I'd make that before
a beforeEach
. Or, since it's short, intercept the different things and visit at the start of each test.
Another option is to not use aliases, declare some let
variables before your before
block, cy.wait
for the interceptions in the before
and assign the results to the variables. Then those variables are in scope for your later tests.magnificent-lamp-25446
01/10/2022, 6:33 PMjavascript
describe('Testes', () => {
before(() => {
cy.loginAzure();
cy.intercept(
{ method: "GET", url: "URL1" },
{ fixture: "FIXTURE1" }
).as("ALIAS1");
cy.intercept(
{ method: "GET", url: "URL2" },
{ fixture: "FIXTURE2" }
).as("ALIAS2");
cy.visit("/PAGE");
});
describe("checking request paramaters", () => {
it("the three requests should be called with the correct paramaters", () => {
const parametrosAnoMes = {
// some parameters
};
const parametrosAnoMesCorredor = {
// some parameters
};
cy.wait("@ALIAS1").then(({ request }) => {
cy.decodeQueryParams(request.url).should('deep.equal', parametrosAnoMesCorredor);
});
cy.wait("@ALIAS2").then(({ request }) => {
cy.decodeQueryParams(request.url).should('deep.equal', parametrosAnoMes);
});
})
})
describe("component test", () => {
// Some components checks
})
});
What do you think? Is it an ok solution or is it a bad practice to rely on the first "it" block to make those assertions?wonderful-match-15836
01/10/2022, 6:45 PMcy.visit
in beforeEach
callbacks. It's especially a good idea if your tests do any interactions. But either way, you have options nowmagnificent-lamp-25446
01/10/2022, 6:52 PMmagnificent-lamp-25446
01/10/2022, 6:52 PM