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

Sinon 1.17.0: sinon.createStubInstance cannot be used twice on the same constructor #852

Closed
mantoni opened this issue Sep 24, 2015 · 10 comments

Comments

@mantoni
Copy link
Member

mantoni commented Sep 24, 2015

This is a new issue in Sinon 1.17.0 and it's working fine with 1.16.1:

var a = sinon.createStubInstance((MyThing);
var b = sinon.createStubInstance((MyThing);

Fails on the second line with:

TypeError: Attempted to wrap constructor which is already wrapped
  at checkWrappedMethod (node_modules/sinon/lib/sinon/util/core.js:91)
  at wrapMethod (node_modules/sinon/lib/sinon/util/core.js:121)
  at stub (node_modules/sinon/lib/sinon/stub.js:66)
  at node_modules/sinon/lib/sinon/stub.js:59
  at node_modules/sinon/lib/sinon/walk.js:34
  at forEach (null:null)
  at walk (node_modules/sinon/lib/sinon/walk.js:35)
  at walk (node_modules/sinon/lib/sinon/walk.js:39)
  at walk (node_modules/sinon/lib/sinon/walk.js:39)
  at stub (node_modules/sinon/lib/sinon/stub.js:61)
  at node_modules/sinon/lib/sinon/util/core.js:361
  ...

Environment: Node 4.0.0

@fatso83
Copy link
Contributor

fatso83 commented Sep 24, 2015

I am unable to recreate this? Tried running it with everything from 1.16.1 to the latest master

describe('issue #852', function() {
    function MyThing() {}
    it('should not fail', function() {
        var a = sinon.createStubInstance(MyThing);
        var b = sinon.createStubInstance(MyThing);
    });
});

OK, didn't do a mistiake after all, I still cannot verify this ...

@fatso83
Copy link
Contributor

fatso83 commented Sep 24, 2015

Tried this in Node 0.12 and 4.1, as well as PhantomJS. Never a failing test.

@mantoni
Copy link
Member Author

mantoni commented Sep 24, 2015

Sorry, left this here without further investigating. Had a hell of a day. I have a large test case that has this issue. Will see if I can extract the gist of it tomorrow.

@flexfrank
Copy link

Creating a stub of a subclass reproduces the same error.

describe('', function() {
    var A = function() {};
    var B = function() {};
    B.prototype = Object.create(A.prototype);
    B.prototype.constructor = B;

    it('create stub instance of a subclass', function() {
        var b = sinon.createStubInstance(B);
    });
});
  ✗ create stub instance of a subclass
    TypeError: Attempted to wrap constructor which is already wrapped
        at checkWrappedMethod (node_modules/sinon/pkg/sinon.js:1239)
        at wrapMethod (node_modules/sinon/pkg/sinon.js:1269)
        at stub (node_modules/sinon/pkg/sinon.js:3322)
        at node_modules/sinon/pkg/sinon.js:3315
        at node_modules/sinon/pkg/sinon.js:3220


PhantomJS 1.9.8 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.012 secs / 0.001 secs)

sinon 1.17.0
node v0.12.6

@fatso83
Copy link
Contributor

fatso83 commented Sep 25, 2015

Cool, thanks for contributing, @flexfrank. Verified the bug in Node, so running git bisect tests now to find the regression.

@fatso83
Copy link
Contributor

fatso83 commented Sep 25, 2015

This is a duplicate of #847, so closing this one. Do follow progress on the other.

@fatso83 fatso83 closed this as completed Sep 25, 2015
mroderick added a commit to mroderick/sinon that referenced this issue Sep 25, 2015
traviskaufman added a commit to traviskaufman/Sinon.JS that referenced this issue Sep 25, 2015
mroderick added a commit that referenced this issue Sep 26, 2015
…ructors

Fixes #852: Do not attempt to re-stub constructors
@mroderick
Copy link
Member

Sinon.JS v1.17.1 is now on npm, the website will be updated soon.

@kmiyashiro
Copy link

I'm still getting this error on 1.17.1

node 0.12
phantom 1.9.8

@fatso83
Copy link
Contributor

fatso83 commented Oct 1, 2015

@kmiyashiro that's surprising. Certainly not using the test case above? Do you have a consistent way of reproducing the bug so that it's possible to verify?

@kmiyashiro
Copy link

Not using the test case and I do not have a reduced test case. I was using sinon.createStubInstance(Router) where Router is something that extends a subclass of Backbone.Router using backbone's Backbone.Router.extend. I tried creating a fiddle, but I can't seem to find an https origin that hosts 1.17.1.

var BaseRouter = Backbone.Router.extend(...);
var Router = BaseRouter.extend(...);
sinon.createStubInstance(Router);

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

No branches or pull requests

5 participants