【发布时间】:2019-06-20 15:40:02
【问题描述】:
我想针对元素数组的值进行测试,每个元素的文本内容应该是“a”或“b”之一。
it("should display for adventure & cabin charter when both are the only ones selected", () => {
cy.get("button.expCategoryBtn")
.contains("a")
.click();
cy.get("button.expCategoryBtn")
.contains("b")
.click();
// the following line doesnt work
cy.get("div.tag").each(x => {
// the problem line:
// I want to get the text value of each el & expect
// it to be one of a or b
expect(cy.wrap(x).invoke("text")).to.be.oneOf([
"a",
"b"
]);
});
});
编辑: 我是这样做的:
it("should display for adventure & cabin charter when both are the only ones selected", () => {
cy.get("button.expCategoryBtn")
.contains("Adventure")
.click();
cy.get("button.expCategoryBtn")
.contains("Cabin Charter")
.click();
cy.get("div.tag")
.invoke("text")
.should("include", "adventure")
.should("include", "cabin_charter")
.should("not.include", "science_and_nature");
});
但是,我对此并不满意,并且仍然希望得到一些反馈,了解当我们要断言多个值中的一个时,正确的测试方法是什么。谢谢。
【问题讨论】:
标签: javascript testing bdd cypress