sinon-stub-promise
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -29,4 +29,3 @@ function buildThenable() { | ||
if (this.rejected && onReject) { | ||
onReject(this.rejectValue); | ||
return this; | ||
return this.catch(onReject); | ||
} | ||
@@ -39,3 +38,7 @@ return this; | ||
try { | ||
onReject(this.rejectValue); | ||
const value = onReject(this.rejectValue); | ||
this.resolved = true; | ||
this.rejected = false; | ||
this.resolveValue = value; | ||
this.rejectValue = undefined; | ||
} catch (e) { | ||
@@ -42,0 +45,0 @@ this.rejectValue = e; |
{ | ||
"name": "sinon-stub-promise", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Synchronous Promise stubbing for Sinon.JS", | ||
@@ -5,0 +5,0 @@ "author": "Alex May <alex@substantial.com>", |
var sinon = require('sinon'); | ||
var sinonStubPromise = require('../index'); | ||
var AssertionError = require('chai').AssertionError; | ||
var expect = require('chai').expect; | ||
var chai = require('chai'); | ||
var RSVP = require('rsvp'); | ||
var expect = chai.expect; | ||
var assert = chai.assert; | ||
@@ -32,7 +34,7 @@ sinonStubPromise(sinon); | ||
}); | ||
it('can resolve multiple times with the same value', function() { | ||
var secondResolvedValue = null; | ||
promise.resolves('resolve value'); | ||
promise().then(function(arg) { | ||
@@ -42,3 +44,3 @@ resolveValue = arg; | ||
expect(resolveValue).to.equal('resolve value'); | ||
promise().then(function(arg) { | ||
@@ -191,2 +193,28 @@ secondResolvedValue = arg; | ||
it('handles catches that succeed', function(done) { | ||
promise.rejects('an error'); | ||
promise().then(f, function(e) { | ||
expect(e).to.equal('an error'); | ||
return 'no error'; | ||
}).then(function (d) { | ||
expect(d).to.equal('no error'); | ||
done(); | ||
}) | ||
}); | ||
it('handles catches that fail', function(done) { | ||
promise.rejects('an error'); | ||
promise().then(f, function(e) { | ||
expect(e).to.equal('an error'); | ||
throw new Error('another'); | ||
}).then(function () { | ||
done(new Error("Promise did not throw")) | ||
}, function (e) { | ||
expect(e.message).to.equal('another'); | ||
done(); | ||
}) | ||
}); | ||
describe('chaining', function() { | ||
@@ -303,3 +331,20 @@ it('supports then chaining', function(done) { | ||
}); | ||
it('does execute additional then blocks when an error has been caught', function(done) { | ||
promise.resolves(); | ||
promise() | ||
.then(function() { | ||
throw new Error('Stop the insanity'); | ||
}) | ||
.catch(function(error) { | ||
expect(error.message).to.eql('Stop the insanity'); | ||
return 'No more error'; | ||
}) | ||
.then(function (r) { | ||
expect(r).to.eql('No more error'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
14047
7
352