lively-balloon-98986
01/15/2023, 1:27 PMgreen-controller-97889
01/15/2023, 10:11 PMjs
const titles = [
"title 0",
"title 1",
"title 2",
];
js
cy.get("[data-cy='subheader']").each((item, index) => {
cy.wrap(item).should("contain.text", titles[index]);
});
or
js
cy
.get('.todo').should( items => {
expect(items[0]).to.contain.text('wash dishes')
expect(items[1]).to.contain.text('buy milk')
})
How can I make this work for any number of elements ?green-controller-97889
01/15/2023, 11:03 PMred-smartphone-84750
01/15/2023, 11:04 PMgray-kilobyte-89541
01/15/2023, 11:08 PMgray-kilobyte-89541
01/15/2023, 11:08 PMcy.intercept
see https://on.cypress.io/intercept or my paid cause https://cypress.tips/courses/network-testinggreen-controller-97889
01/15/2023, 11:09 PM.some
:
js
cy.get('.list-item').then(($listItems) => {
let matched = $listItems.toArray().some((item) => item.textContent.includes('example'));
expect(matched).to.be.true;
});
But if the last title is correct then matched is true, disregarding the iterations before it.
I've also tried:
js
cy.get("[data-cy='subheader']").should(items => {
expect((items[0]).to.contain.text(titles[0]))
expect((items[1]).to.contain.text(titles[1]))
expect((items[2]).to.contain.text(titles[2]))
});
But this returns Cannot read properties of undefined (reading 'contain')
green-controller-97889
01/15/2023, 11:21 PMjs
cy.get("[data-cy='subheader']").each(subheader => {
cy.wrap(subheader).invoke("text").should("be.oneOf", titles);
})
red-smartphone-84750
01/15/2023, 11:44 PMdescribe("template spec", () => {
it("test", () => {
cy.intercept("GET", "http://localhost:3001/countries", {
fixture: "../../../src/mocks/countries.json",
});
cy.visit("http://localhost:3000/");
});
});
That info should populate a dropdown that appear on localhost:3000 form. But I am getting this error.red-smartphone-84750
01/16/2023, 12:37 AMconst genders = require("../../../src/mocks/genders.json");
const countries = require("../../../src/mocks/countries.json");
const jockeys = require("../../../src/mocks/jockeys.json");
describe("template spec", () => {
beforeEach("before", () => {
cy.intercept("GET", "http://localhost:3001/genders", {
body: genders,
}).as("getGenders");
cy.intercept("GET", "http://localhost:3001/countries", {
body: countries,
}).as("getCountries");
cy.intercept("GET", "http://localhost:3001/jockeys", {
body: jockeys,
}).as("getJockeys");
});
it("Llenar formulario", () => {
cy.visit("http://localhost:3000/");
});
});
Using require
. What do you think guys?colossal-table-38461
01/16/2023, 5:20 AMbroad-analyst-94821
01/16/2023, 10:26 AMcolossal-mouse-44047
01/16/2023, 10:37 AMbroad-analyst-94821
01/16/2023, 10:38 AMtestIsolation:false
hallowed-autumn-34625
01/16/2023, 12:29 PMimportant-smartphone-8814
01/16/2023, 2:57 PMgray-kilobyte-89541
01/16/2023, 3:49 PMexpect
gray-kilobyte-89541
01/16/2023, 3:50 PMfuture-glass-89764
01/16/2023, 4:17 PMhelpful-truck-53930
01/16/2023, 4:33 PMdazzling-salesclerk-15570
01/16/2023, 6:34 PMgray-kilobyte-89541
01/16/2023, 7:26 PMmodern-dawn-86006
01/16/2023, 7:37 PMmodern-dawn-86006
01/16/2023, 7:51 PMmodern-dawn-86006
01/16/2023, 7:52 PMmodern-dawn-86006
01/16/2023, 7:54 PMcy.get('items').eq(0).invoke('text').should('be.oneOf', ["title 0", "title 1", "title 2"])
modern-dawn-86006
01/16/2023, 7:56 PMfor (let i = 0; i < index; i++) {
cy.get('items').eq(index).invoke('text').should('be.oneOf', ["title 0", "title 1", "title 2"])
}
modern-dawn-86006
01/16/2023, 8:36 PMgray-kilobyte-89541
01/16/2023, 8:40 PM