Skip to content

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 authored and Franck Romano committed Oct 1, 2019
1 parent 4004130 commit d264cb5
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 @@ -2,6 +2,7 @@

var referee = require("referee");
var sinon = require("../../lib/sinon");
var createStub = require("../../lib/sinon/stub");
var assert = referee.assert;
var refute = referee.refute;

Expand Down Expand Up @@ -298,4 +299,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 @@ -108,39 +108,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 d264cb5

Please sign in to comment.