【发布时间】:2023-03-18 17:39:01
【问题描述】:
我正在尝试使用 Expect 测试错误,但在此 try/catch 块中,日志无法正常工作。在此块之前,我可以看到数组正在由输入填充...我不明白为什么脚本没有进入 try/catch 块,因此可以进行测试并返回正确的错误消息.任何帮助将不胜感激。代码:
inputs = ["fname", "surname"];
for (var i = 0; i < inputs.length; i++) {
var errors=[];
errors.push(inputs[i]);
console.log("FNAME"+inputs[0]+ "SURNAME" +inputs[1]); //works
try {
if (inputs[i] == 0) {
expect(inputs[i]).to.be.NaN;
expect(inputs[i]).to.have.length.above(1);
console.log("FNAME FIELD IS " + inputs[0]); //NOT WORKING
}
if (inputs[i] == 1) {
expect(inputs[i]).to.be.NaN;
expect(inputs[i]).to.have.length.above(1);
console.log("SURNAME FIELD IS " + inputs[1]); //not working
}
return "OK";
} catch (errors) {
console.log("STACK" + errors(inputs[0]));
//save(errors);
return errors;
}
}
【问题讨论】:
标签: javascript arrays node.js try-catch