我正在使用 NightwatchJs 框架进行测试。我需要将实际值与一组有效值进行比较。但是,当在预期结果数组中找到正确的值时,我当前的实现会引发多次失败。我想显示测试的输出,只有当没有值匹配或测试通过时。
鉴于我有以下数组:
var topDesktop = [['728', '90'], ['970', '250'], ['970', '90'], ['980', '250'], ['980', '240'], ['980', '120'], ['980', '90'], ['1000', '90'], ['1000', '300']];
我想知道当前值是否在允许的值(topDesktop 数组)内。
var actual = result.toString();
for(var i = 0; i < topDesktop.length; i++){
client.assert.equal(actual, topDesktop[i]);
}
出于显而易见的原因,输出是 for 循环的结果:
✔ Passed [equal]: 728,90 == [ '728', '90' ]
✖ Failed [equal]: ('728,90' == [ '970', '250' ]) - expected "970,250" but got: "728,90"
✖ Failed [equal]: ('728,90' == [ '970', '90' ]) - expected "970,90" but got: "728,90"
✖ Failed [equal]: ('728,90' == [ '980', '250' ]) - expected "980,250" but got: "728,90"
.
.
.
我想避免的是每次比赛尝试都失败。有什么绝妙的主意吗?