@@ -16,6 +16,10 @@ function ownCallback(err, httpResponse, body) {
}catch (e){}
}
if (self._rp_then_invoked!==true){
return;
}
if (err){
self._rp_reject({
error:err,
@@ -40,6 +44,7 @@ function ownCallback(err, httpResponse, body) {
self._rp_resolve(body);
}
}
}
varoriginalInit=request.Request.prototype.init;
@@ -65,8 +70,13 @@ request.Request.prototype.then = function (onFulfilled, onRejected) {
varself=this;
if (self._rp_then_invoked===true){
thrownewError('Request-Promise currently only allows to call the rp(...).then(...) method once. Please use chaining like rp(...).then(...).then(...) instead.');
xit('with using the then method at the same time');
xit('and still work if the callback throws an exception');
it('without using the then method and no callback provided',function (done){
rp('http://localhost:4000/234');// 234 is only used here.
setTimeout(function (){
if (lastResponseBody!=='GET /234'){
done (newError('The server did not receive the request!'));
}else{
done();
}
},20);
});
});
describe('should be Promises/A+ compliant',function (){
xit('and take only a fulfilled handler');
xit('and take only a rejected handler');
xit('and allow calling then after the request already finished');
xit('by allowing chaining');
it('but not allow the then method to be invoked more than once',function (){
varreq=rp('http://localhost:4000/200');
req.then(function (){},function (){});
// FIXME: Using the following line instead of the previous one produces an error.
// req.then(function () {});
expect(function (){req.then();}).to.throw('Request-Promise currently only allows to call the rp(...).then(...) method once. Please use chaining like rp(...).then(...).then(...) instead.');