我是量角器的新手。我想从protractor.promise.defer.reject
中捕获异常var action = function(){
var defer = protractor.promise.defer()
ASYN_POST(function(result){
if(result){
defer.fulfill();
}else{
defer.reject(new Error('post failure'));
};
});
return defer.promise;
};
it('example', function(done){
action().then(console.log).catch(function(){
console.log('catch you');
});
});
执行else分支时,不会调用catch函数。我该如何修复我的代码。感谢
输出:
defer.reject(new Error('catch you'));
^
Error: downgrading failure
at Request._callback (/vagrant/vosaas438/spec/versions-api.spec.js:93:26)
at Request.self.callback (/usr/local/lib/node_modules/request/request.js:199:22)
at emitTwo (events.js:87:13)
at Request.emit (events.js:172:7)
答案 0 :(得分:0)
我也遇到过.catch()问题。尝试为.then(callbackForSuccess,callbackForReject)提供第二个函数;它也将被用作拒绝的回调。
it('example', function(done){
action().then(console.log, function(){
console.log('catch you');
});
});