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

createStubInstance override and null return values #1957

Closed
spicalous opened this issue Dec 10, 2018 · 1 comment
Closed

createStubInstance override and null return values #1957

spicalous opened this issue Dec 10, 2018 · 1 comment

Comments

@spicalous
Copy link

Describe the bug
sinon.createStubInstance was extended recently to allow overrides such as:

sinon.createStubInstance(AClass, {
  aMethod: "a string",
  aChainableMethod: sinon.stub().returnsThis()
});

Theres a small issue which prevents a user from returning null values

To Reproduce

sinon.createStubInstance(AClass, {
  aMethod: null
});

Expected behavior
The library should correctly create a stub instance with a stub method returning null

Reason
Theres an initial check whether the override is a stub by checking if createStubInstance property exists on the return value https://github.com/sinonjs/sinon/blob/master/lib/sinon/stub.js#L85

This throws when we try to check a property of null

Context (please complete the following information):

  • Library version: Current latest v7.x
  • Environment: OSX

Thanks!
Let me know if it makes sense, I can help create a PR for it

@mroderick
Copy link
Member

Thank you for your detailed analysis of the bug, it looks like an interesting one!
A pull request would be very welcome 👍

spicalous pushed a commit to spicalous/sinon that referenced this issue Dec 11, 2018
franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
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