Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1487: incorrect withArgs().returnValue #1490

Closed
wants to merge 3 commits into from

Conversation

kbtknr
Copy link

@kbtknr kbtknr commented Jul 18, 2017

Fix issue #1487
The cause of this bug is that createCallProperties(matching) is never called to make returnValue and exception.

@coveralls
Copy link

coveralls commented Jul 18, 2017

Coverage Status

Coverage increased (+0.004%) to 95.006% when pulling caa0bf1 on takasmiley:issues/#1487 into 259a330 on sinonjs:master.

@coveralls
Copy link

coveralls commented Jul 18, 2017

Coverage Status

Coverage increased (+0.004%) to 95.006% when pulling 4a40f80 on takasmiley:issues/#1487 into 259a330 on sinonjs:master.

@fatso83 fatso83 self-assigned this Jul 18, 2017
Copy link
Contributor

@fatso83 fatso83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, for yet another pull request, @takasmiley! I did have some objections to it, though, which is mainly summed up in KISS :-) The regression test is just too complex for this quite simple bug. Just simplify it. I think you could probably get away with 1/3 of the code.

@@ -124,6 +124,39 @@ describe("stub", function () {
refute.isNull(stub.withArgs(1).firstCall);
});

describe("should work firstCall and lastCall", function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this test in issues-test.js with the description "#1487 - withArgs() returnValue" and split the testcase into two separate testcases. Right now it could fail at any of the eight assertions.

@@ -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"; } }; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great that you could directly use the test case from #1487, but I think all the nested functions here obscure the actual bug and what is going on.

It really shouldn't be necessary with this much ceremony.

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

assert.isTrue(this.stub.calledWith(testComponentA));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a test for this in call-test.js. This can be deleted.

var component = this.stub(testComponentA)(config);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - already tested here.

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

assert.isFunction(component.render);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. You are testing that the test stub you created yourself above is working, not the library.

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. Not necessary to test your test code. Maybe you try to assert that stubbing functionality works in general, but we already know that through other tests. #1487 is explicitly about returnValues in combo with withArgs and lastCall/firstCall.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two assertions could be one test: "it should return the same for getCall(0).returnValue and returnValues[0]", where you simply assert equality between the two calls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do note that having calledWith is an uneeded complexity that has little with the core of the original issue. Just assert equality between the returnValue.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do the same for this call.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been a separate, second test to avoid confusion, where you might call the stub twice, just to be sure that getCall(1).returnValue and lastCall.returnValue returns the same.

@brian-mann
Copy link

Really looking forward to having this land!

@fatso83
Copy link
Contributor

fatso83 commented Jul 26, 2017

@brian-mann, if you check out the branch and fix the remaining issues I mentioned above you can get it out whenever you want. Just push it out and open another PR, leaving the original commit to recognize the original work. I'll see to it that it gets merged pronto.

@brian-mann
Copy link

Okay @chrisbreiding is gonna hack on this.

@fatso83
Copy link
Contributor

fatso83 commented Jul 28, 2017

This just got merged as part of #1500, so closing. Thanks a lot for the work, @takasmiley! We appreciate it greatly.

@fatso83 fatso83 closed this Jul 28, 2017
@fatso83
Copy link
Contributor

fatso83 commented Jul 28, 2017

This will be out as soon as we find out what is causing the problems in #1498.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants