Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
Merge commit '4a40f80b79f3f74558e2c7c5890cc299ea276984'
Browse files Browse the repository at this point in the history
* commit '4a40f80b79f3f74558e2c7c5890cc299ea276984':
  Use property of this, not variable
  Rename variable name
  Fix sinonjs#1487: incorrect withArgs().returnValue
  • Loading branch information
brian-mann committed Jul 26, 2017
2 parents 251ad90 + 4a40f80 commit db37ec8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/sinon/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ var spyApi = {

// Make return value and exception available in the calls:
createCallProperties.call(this);
matchings.forEach(function (matching) {
createCallProperties.call(matching);
});

if (exception !== undefined) {
throw exception;
Expand Down
33 changes: 33 additions & 0 deletions test/stub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@ describe("stub", function () {
refute.isNull(stub.withArgs(1).firstCall);
});

describe("should work firstCall and lastCall", function () {
var testComponentA = function () { return { render: function () { return "test a"; } }; };
var testComponentB = function () { return { render: function () { return "test b"; } }; };

beforeEach(function () {
var fakeComponent = function (variant) {
return createStub().returns({
render: createStub().returns("fake component " + variant)
});
};
this.stub = createStub().throws("Nothing set");
this.stub.withArgs(testComponentA).returns(fakeComponent("a"));
this.stub.withArgs(testComponentB).returns(fakeComponent("b"));
});

it("returnValues", function () {
var config = { option: "a" };
var component = this.stub(testComponentA)(config);

assert.isTrue(this.stub.calledWith(testComponentA));
assert.isFalse(this.stub.calledWith(testComponentB));

assert.isFunction(component.render);
assert.equals(component.render(), "fake component a");

assert.isTrue(this.stub.withArgs(testComponentA).returnValues[0].calledWith(config));
assert.isTrue(this.stub.withArgs(testComponentA).getCall(0).returnValue.calledWith(config));

assert.isTrue(this.stub.withArgs(testComponentA).firstCall.returnValue.calledWith(config));
assert.isTrue(this.stub.withArgs(testComponentA).lastCall.returnValue.calledWith(config));
});
});

describe(".returns", function () {
it("returns specified value", function () {
var stub = createStub.create();
Expand Down

0 comments on commit db37ec8

Please sign in to comment.