假设有三个数组。
const initialArray = ['He', 'She', 'It']
const middleArray = ['is', 'was', 'were']
const lastArray = ['a dog', 'a cat', 'a wizard']
我的意思是,如果出现这 3 种组合中的任何一个,则该句子是有效的,但该句子需要是
'initialArray middleArray lastArray'
只有这个序列组合是正确的,其他都是错误的
我正在尝试编写类似这样的硬编码内容,但当变量数量增加时它就不起作用了。
cy.get(`.${className} .legend_title`).should((key) => {
let mytext = key.text();
expect(mytext.trim()).to.be.oneOf([
'He is a dog',
"He is a cat",
'He is a wizard',
'She is a dog', .......
]);
});
最佳答案
更简单的方法是使用正则表达式来匹配句子。如果您选择,可以通过编程方式创建匹配器。
这是一个工作 example .
// regex for simpilicity
const matcher = /(He|She|It)\s(is|was|were)\s(a)\s(dog|cat|wizard)/i;
cy.get("#sentence").invoke("text").should("match", matcher);
关于cypress - 有什么方法可以用 cypress 测试句子的所有可能组合吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72669434/