sinon-stub-promise
Advanced tools
Comparing version 0.0.1 to 0.0.2
31
index.js
@@ -5,30 +5,23 @@ | ||
return { | ||
_reject: function(onReject) { | ||
var rejectedValue = onReject(this.rejectValue); | ||
// update reject value for next promise in chain | ||
if (rejectedValue) { | ||
this.rejectValue = rejectedValue; | ||
} | ||
}, | ||
then: function(onFulfill, onReject) { | ||
if (this.resolved) { | ||
var resolvedValue = onFulfill(this.resolveValue); | ||
var returned = onFulfill(this.resolveValue); | ||
// promise returned, return that for next handler in chain | ||
if (resolvedValue && resolvedValue.then) { | ||
return resolvedValue; | ||
if (returned && returned.then) { | ||
return returned; | ||
} | ||
// update resolve value for next promise in chain | ||
if (resolvedValue) { | ||
this.resolveValue = resolvedValue; | ||
if (returned) { | ||
this.resolveValue = returned; | ||
} | ||
return this; | ||
} | ||
if (this.rejected && onReject) { | ||
this._reject(onReject); | ||
onReject(this.rejectValue); | ||
return this; | ||
} | ||
return this; | ||
@@ -38,6 +31,6 @@ }, | ||
catch: function(onReject) { | ||
if (this.rejected && onReject) { | ||
this._reject(onReject); | ||
if (this.rejected) { | ||
onReject(this.rejectValue); | ||
return this; | ||
} | ||
return this; | ||
@@ -44,0 +37,0 @@ }, |
{ | ||
"name": "sinon-stub-promise", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Synchronous Promise stubbing for Sinon.JS", | ||
@@ -5,0 +5,0 @@ "author": "Alex May <alex@substantial.com>", |
@@ -155,3 +155,3 @@ var sinon = require('sinon'); | ||
it('returns intermediate values from then', function() { | ||
it('returns intermediate values', function() { | ||
promise.resolves(); | ||
@@ -168,16 +168,3 @@ | ||
}); | ||
it('returns intermediate values from catch', function() { | ||
promise.rejects(); | ||
var intermediateValue; | ||
promise().catch(function() { | ||
return 'intermediate value'; | ||
}).catch(function(value) { | ||
intermediateValue = value; | ||
}); | ||
expect(intermediateValue).to.eql('intermediate value'); | ||
}); | ||
}); | ||
}); |
8358
187