From d264cb570c3212ced670a922f6afa5704e1453a1 Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Thu, 27 Jul 2017 15:36:00 -0400 Subject: [PATCH] move and write reduced test case for #1487 --- test/issues/issues-test.js | 17 +++++++++++++++++ test/stub-test.js | 33 --------------------------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index d99ae2b29..7e3c8c653 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -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; @@ -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"); + }); + }); }); diff --git a/test/stub-test.js b/test/stub-test.js index 566e36267..19579aebc 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -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();