Skip to content

Commit

Permalink
propagates promiseLibrary to new stub behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMuller committed Jul 12, 2017
1 parent 9365d49 commit d14d296
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/sinon/behavior.js
Expand Up @@ -105,6 +105,10 @@ var proto = {
delete behavior.createBehavior;
behavior.stub = stub;

if (stub.defaultBehavior && stub.defaultBehavior.promiseLibrary) {
behavior.promiseLibrary = stub.defaultBehavior.promiseLibrary;
}

return behavior;
},

Expand Down
31 changes: 31 additions & 0 deletions test/issues/issues-test.js
Expand Up @@ -251,6 +251,37 @@ describe("issues", function () {
});
});

describe("#1474 - stub.onCall", function () {
it("should preserve promise library", function () {
var promiseLib = {
resolve: function (value) {
var promise = Promise.resolve(value);
promise.tap = function () {
return "tap " + value;
};

return promise;
}
};
var stub = sinon.stub().usingPromise(promiseLib);

stub.resolves("resolved");
stub.onSecondCall().resolves("resolved again");

var first = stub();
var second = stub();

assert.isFunction(first.then);
assert.isFunction(first.tap);

assert.isFunction(second.then);
assert.isFunction(second.tap);

assert.equals(first.tap(), "tap resolved");
assert.equals(second.tap(), "tap resolved again");
});
});

if (typeof window !== "undefined") {
describe("#1456", function () {
var sandbox;
Expand Down

0 comments on commit d14d296

Please sign in to comment.