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

Sandbox stubbing static function property throws error #1445

Closed
raulmatei opened this issue Jun 2, 2017 · 5 comments
Closed

Sandbox stubbing static function property throws error #1445

raulmatei opened this issue Jun 2, 2017 · 5 comments

Comments

@raulmatei
Copy link
Contributor

raulmatei commented Jun 2, 2017

  • Sinon version : 2.3.2
  • Environment: Node
  • Other libraries you are using: Mocha

What did you expect to happen?
Should be able to stub a function static property. It worked with v2.2.0

What actually happens
Throws an error:
TypeError: Attempted to wrap object property content as function

How to reproduce

// code
const fn = () => false;

fn.content = {
  a: 'A',
  b: 'B',
};
// test
before(() => {
  sandbox = sinon.sandbox.create();
  
  sandbox.stub(fn, 'content').value({
    a: '__A__',
    b: '__B__',
  });
});

after(() => {
  sandbox.restore();
});
@raulmatei raulmatei changed the title Sandbox stub static function property throws error Sandbox stubbing static function property throws error Jun 2, 2017
@fatso83
Copy link
Contributor

fatso83 commented Jun 2, 2017

Seems like we have a regression. Could it be related to the new getter/setter stubbing functionality, @lucasfcosta?

@raulmatei
Copy link
Contributor Author

raulmatei commented Jun 2, 2017

It looks to me that this was introduced with this commit 278c2ce#diff-048fb1194de4b43f7f7e45758f900749R21, changing that check to:

var isStubbingNonFuncProperty = (typeof object === "object" || typeof object === "function")
                                && typeof property !== "undefined"
                                && (typeof actualDescriptor === "undefined"
                                || typeof actualDescriptor.value !== "function")
                                && typeof descriptor === "undefined";

seems to make it work.

Thanks,
Raul

@lucasfcosta
Copy link
Member

lucasfcosta commented Jun 4, 2017

@fatso83, yup! Good catch @raulmatei.

I missed a check to see if the passed object itself was a function.

That should indeed solve the problem. I'll be more than happy to review a PR from you if you'd like to sendo one. Thanks for the help 😄

@raulmatei
Copy link
Contributor Author

raulmatei commented Jun 6, 2017

@lucasfcosta will come with a PR later this week. Hope it won't be too late for others.

Raul.

@lucasfcosta
Copy link
Member

Hi folks. I can't close issues but I believe this one is done.

@mantoni mantoni closed this as completed Jun 8, 2017
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

4 participants