使用GitHub repository for checkit中带有无效正文的示例,当我使用异步版本在Node.js 6.2.2上运行它时,它不会抛出错误(或者至少,它不是&n #39; t catched - 因此没有控制台输出):
<!DOCTYPE html>
<html>
<head>
<script>
function handleVisibility(box){
var visible = (box.checked) ? "block": "none";
box.parentElement.nextSibling.style.display = visible;
}
</script>
</head>
<body>
<div id="divTransfer">
<input id="cbTransferRefer" type="checkbox" value="TransferRefer" onClick = "handleVisibility(this)">Transfer/Refer<br>
</div>
<div id="pTransferTypes" style="display:none" >
Transfer Types:
<select>
<option value="referred">Referred</option>
<option value="internalTaskForm">Escalated via Internal Task Form</option>
<option value="cci">Escalated via CCI</option>
<option value="pdf">Escalated via PDF Form</option>
<option value="transferred">Transferred</option>
</select>
</div>
<div id="divTemplate">
<input id="cbTemplateRefer" type="checkbox" value="TemplateRefer" onClick = "handleVisibility(this)">Template/Refer<br>
</div>
<div id="pTemplateTypes" style="display:none" >
Template Types:
<select>
<option value="referred">Referred</option>
<option value="internalTaskForm">Escalated via Internal Task Form</option>
<option value="cci">Escalated via CCI</option>
<option value="pdf">Escalated via PDF Form</option>
<option value="transferred">Transferred</option>
</select>
</div>
</body>
</html>
从存储库运行测试时,所有测试都是绿色的(包含传递给var checkit = new Checkit({
firstName: 'required',
lastName: 'required',
email: ['required', 'email']
});
var body = {
firstName: 'Tim',
lastName: 'Griesser',
githubUsername: 'tgriesser'
};
checkit.run(body).then(function(validated) {
console.log(validated);
}).catch(Checkit.Error, function(err) {
console.log(err.toJSON());
})
的无效对象的测试。
使用有效的身体运行样本时,一切正常。 它只是不起作用的错误路径。
答案 0 :(得分:0)
找到解决方案:
var checkit = new Checkit({
firstName: 'required',
lastName: 'required',
email: ['required', 'email']
});
var body = {
firstName: 'Tim',
lastName: 'Griesser',
githubUsername: 'tgriesser'
};
checkit.run(body).then(function (validated) {
console.log(validated);
}).catch(err => {
console.log(err.toJSON());
});
区别在于catch()
声明:
来自网站的示例:.catch(Checkit.Error, function(err) {})
测试/工作解决方案:.catch(function(err) {})
预期结果:
{ email: [ 'The email is required' ] }