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

Commit

Permalink
move and write reduced test case for sinonjs#1487
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Jul 27, 2017
1 parent 4a40f80 commit 0fcb839
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
17 changes: 17 additions & 0 deletions test/issues/issues-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var referee = require("referee");
var sinon = require("../../lib/sinon");
var sinonSandbox = require("../../lib/sinon/sandbox");
var createStub = require("../../lib/sinon/stub");
var configureLogError = require("../../lib/sinon/util/core/log_error.js");
var assert = referee.assert;
var refute = referee.refute;
Expand Down Expand Up @@ -314,4 +315,20 @@ describe("issues", function () {
assert.equals(window.innerHeight, 111);
});
});

describe("#1487 - withArgs() returnValue", function () {
beforeEach(function () {
this.stub = createStub().throws("Nothing set");
this.stub.withArgs("arg").returns("return value");
this.stub("arg");
});

it("sets correct firstCall.returnValue", function () {
assert.equals(this.stub.withArgs("arg").firstCall.returnValue, "return value");
});

it("sets correct lastCall.returnValue", function () {
assert.equals(this.stub.withArgs("arg").lastCall.returnValue, "return value");
});
});
});
33 changes: 0 additions & 33 deletions test/stub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,39 +124,6 @@ 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 0fcb839

Please sign in to comment.