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

stub#firstCall seems broken on sinon v2.3.6 #1476

Closed
HugoMuller opened this issue Jun 29, 2017 · 6 comments
Closed

stub#firstCall seems broken on sinon v2.3.6 #1476

HugoMuller opened this issue Jun 29, 2017 · 6 comments
Labels

Comments

@HugoMuller
Copy link
Contributor

Hello,

First of all, thanks for the work done :)

Today, one of our unit tests has failed after the update of sinon. (v2.3.5 -> v2.3.6)
We think the latest release introduced a regression.

  • Sinon version : 2.3.6
  • Environment : Debian Jessie, Node v6.11.0

What did you expect to happen?
I expect both stub.getCall(0) and stub.firstCall to return the same thing, even with a stub created with withArgs.

What actually happens
When I create a stub responding to particular arguments with stub.withArgs, this stub can't be inspected with firstCall.
stub.getCall(0) works fine but stub.firstCall returns null. In the previous release (v2.3.5), calling stub.getCall(0) and getting stub.firstCall produced the same result.
The same issue can be observed with secondCall and thirdCall as well.

How to reproduce

const sinon = require('sinon');
const stub = sinon.stub();

stub.withArgs('broken').returns(42);
stub('broken');

stub.withArgs('broken').callCount; // 1
stub.withArgs('broken').calledOnce; // true
stub.withArgs('broken').returnValues[0]; // 42
stub.withArgs('broken').getCall(0) // the first call
stub.withArgs('broken').firstCall; // null
@mroderick
Copy link
Member

Thank you for the easy to follow regression report!

With a slightly modified version of your test (below) and git bisect, I've been able to find the first failing commit: 0e77b31

// test/issues/issue-1476-test.js
"use strict";

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

describe.only("Issue #1476 - withArgs.firstCall, when stub has been called", function () {
    it("must not be null", function () {
        var stub = sinon.stub();

        stub.withArgs("broken").returns(42);
        stub("broken");

        refute.equals(stub.withArgs("broken").firstCall, null);
    });
});

I have yet to determine why it is failing

@fatso83
Copy link
Contributor

fatso83 commented Jun 30, 2017

@HugoMuller, could you check if the issue above is fixed by checking out #1478?

@fatso83 fatso83 closed this as completed in c280916 Jul 3, 2017
fatso83 added a commit that referenced this issue Jul 3, 2017
Fix #1476: stub#firstCall seems broken on sinon v2.3.6
@HugoMuller
Copy link
Contributor Author

Hello,

sorry for the delay :(
I run my test with your patch and it seems to work perfectly now.
Thank you

@mroderick
Copy link
Member

This has been published as v2.3.7, thank you all!

@jvanoostveen
Copy link

Hmm it seems with this patch (in 2.3.7) withArgs().lastCall is broken.
TypeError: Cannot read property 'lastCall' of undefined

@HugoMuller
Copy link
Contributor Author

Hello @jvanoostveen.
Can you explain a little bit? What are the steps to reproduce this?
withArgs() always returns a fake (stub or spy), or eventually throws an error when called after onCall().

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

Successfully merging a pull request may close this issue.

4 participants