gpt4 book ai didi

cypress - 如何比较 Cypress 中的数组?

转载 作者:行者123 更新时间:2023-12-03 18:34:36 25 4
gpt4 key购买 nike

我想将数组中存在的数据与在 cypress 中使用 .each 从类中检索到的数据进行比较?

使用下面的代码,我尝试使用下面的代码迭代 FileType 数组。

const Filetype = ['Access', 'Excel', 'Text/CSV','PDF','JSON','dsdsd'];
const te = cy.wrap($bodyFind).find('.data-sourcename').should('have.length',6).each(($li) => { cy.log($li.text()); });

te.each(($text)=> {
cy.log("Te" + $text);
//prints ['Access','Excel','Text/CSV','PDF','JSON','XML'];
});

// Converted FileType Array to Cypress object using cy.wrap command.
const cywrap = cy.wrap(Filetype);
te.each((e1)=>cywrap.each((e2)=> {
if(e1 == e2) {
expect(e1).equals(e2);
}
}));

但是e1和e2的值是一样的。
期望应该失败,“dsdsd”等于“XML”
而它通过'dsdsd'等于'dsdsd'

最佳答案

您可以使用 map这里。

const filetypes = ['Access', 'Excel', 'Text/CSV','PDF','JSON','dsdsd'];
cy.get('.data-sourcename').should(($els) => {
// map jquery elements to array of their innerText
const elsText = $els.toArray().map(el => el.innerText)
expect(elsText).to.deep.eq(filetypes)
})

关于cypress - 如何比较 Cypress 中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58110351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com