sinon-stub-promise
Advanced tools
Comparing version 2.1.0 to 3.0.0
@@ -0,1 +1,7 @@ | ||
## [v3.0.0] | ||
> July 16, 2016 | ||
- **Major:** Only invoke onResolve/onReject when stub.resolve()/stub.reject() | ||
called ([#18](https://github.com/substantial/sinon-stub-promise/pull/18)) | ||
## [v2.0.0] | ||
@@ -2,0 +8,0 @@ > April 13, 2016 |
24
index.js
function buildThenable() { | ||
return { | ||
onFulfilled: [], | ||
onRejected: [], | ||
onFinally: [], | ||
then: function(onFulfill, onReject) { | ||
@@ -31,2 +34,8 @@ try { | ||
} | ||
if (!this.rejected && onFulfill) { | ||
this.onFulfilled.push(onFulfill); | ||
} | ||
if (!this.resolved && onReject) { | ||
this.onRejected.push(onReject); | ||
} | ||
return this; | ||
@@ -48,2 +57,5 @@ }, | ||
} | ||
if (!this.resolved) { | ||
this.onRejected.push(onReject); | ||
} | ||
return this; | ||
@@ -55,3 +67,5 @@ }, | ||
callback(); | ||
return; | ||
} | ||
this.onFinally.push(callback); | ||
} | ||
@@ -66,2 +80,7 @@ }; | ||
this.thenable.resolveValue = value; | ||
this.thenable.onFulfilled | ||
.concat(this.thenable.onFinally) | ||
.forEach(function(callback) { | ||
callback(value); | ||
}); | ||
return this; | ||
@@ -74,2 +93,7 @@ } | ||
this.thenable.rejectValue = value; | ||
this.thenable.onRejected | ||
.concat(this.thenable.onFinally) | ||
.forEach(function(callback) { | ||
callback(value); | ||
}); | ||
return this; | ||
@@ -76,0 +100,0 @@ } |
{ | ||
"name": "sinon-stub-promise", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Synchronous Promise stubbing for Sinon.JS", | ||
@@ -5,0 +5,0 @@ "author": "Alex May <alex@substantial.com>", |
@@ -70,3 +70,14 @@ var sinon = require('sinon'); | ||
}); | ||
it('does resolve synchronously when explicitly resolved AFTER a then is added', function() { | ||
var resolved = false; | ||
promise().then(function() { | ||
resolved = true; | ||
}); | ||
expect(resolved).to.be.false; | ||
promise.resolves(); | ||
expect(resolved).to.be.true; | ||
}); | ||
it('returns stub from resolves call', function(done) { | ||
@@ -124,3 +135,25 @@ var stub = promise.resolves(); | ||
}); | ||
it('can reject via catch synchronously when explicitly rejected AFTER a catch is added', function() { | ||
var rejected = false; | ||
promise().catch(function() { | ||
rejected = true; | ||
}); | ||
expect(rejected).to.be.false; | ||
promise.rejects(); | ||
expect(rejected).to.be.true; | ||
}); | ||
it('can reject via a then reject function synchronously when explicitly rejected AFTER a then reject function is added', function() { | ||
var rejected = false; | ||
promise().then(f, function() { | ||
rejected = true; | ||
}); | ||
expect(rejected).to.be.false; | ||
promise.rejects(); | ||
expect(rejected).to.be.true; | ||
}); | ||
it('returns stub from rejects call', function(done) { | ||
@@ -182,2 +215,13 @@ var stub = promise.rejects(); | ||
it('invokes finally when promise is resolved after the finally is added', function() { | ||
var finallyCalled = false; | ||
promise().finally(function() { | ||
finallyCalled = true; | ||
}); | ||
expect(finallyCalled).to.be.false; | ||
promise.resolves(); | ||
expect(finallyCalled).to.be.true; | ||
}); | ||
it('invokes finally when promise is rejected', function() { | ||
@@ -194,2 +238,13 @@ promise.rejects(); | ||
it('invokes finally when promise is rejected after the finally is added', function() { | ||
var finallyCalled = false; | ||
promise().finally(function() { | ||
finallyCalled = true; | ||
}); | ||
expect(finallyCalled).to.be.false; | ||
promise.rejects(); | ||
expect(finallyCalled).to.be.true; | ||
}); | ||
it('handles catches that succeed', function(done) { | ||
@@ -196,0 +251,0 @@ promise.rejects('an error'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16685
423