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

Prototype chain and stub breaking behaviours between 1.16.1 and 1.17.1 #867

Closed
armandabric opened this issue Oct 6, 2015 · 2 comments
Closed

Comments

@armandabric
Copy link

I've spot another BC behavior between sinon 0.16.1 and sinon 0.17.1. I've see #860 but I'm not sure this is the same problem.

This code do not throw any error with sinon 1.16.1:

'use strict';

var sinon = require('sinon');

var A = function A() {
    console.log('> Hello A');
};

A.prototype.foo = function foo() {
    return 42;
};


var B = function B() {
    console.log('> Hello B');
};

B.prototype = new A();

B.prototype.foo = function foo() {
    return 51;
};

var b = sinon.createStubInstance(B); // works in 1.6.1, error in 1.7.1 (see below)

In 1.7.1, the last line trigger this error:

TypeError: Attempted to wrap foo which is already wrapped
    at checkWrappedMethod (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/util/core.js:81:29)
    at Object.wrapMethod (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/util/core.js:121:21)
    at stub (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/stub.js:67:26)
    at /Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/stub.js:60:25
    at /Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:26:26
    at Array.forEach (native)
    at walkInternal (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:23:45)
    at walkInternal (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:31:17)
    at walkInternal (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:31:17)
    at Object.walk (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:46:20)
--------------
Error: Stack Trace for original
    at Object.wrapMethod (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/util/core.js:140:34)
    at stub (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/stub.js:67:26)
    at /Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/stub.js:60:25
    at /Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:26:26
    at Array.forEach (native)
    at walkInternal (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:23:45)
    at walkInternal (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:31:17)
    at Object.walk (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/walk.js:46:20)
    at Object.stub (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/stub.js:52:23)
    at Object.sinon.createStubInstance (/Users/spy-seth/workspace/myproject/node_modules/sinon/lib/sinon/util/core.js:361:26)
@mantoni
Copy link
Member

mantoni commented Oct 6, 2015

Thanks for reporting. I'm running into this as well. I'm looking into it right now. It is somewhat related and I might be able to fix both issues.

@armandabric
Copy link
Author

Thank for the fix 👍

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

2 participants