-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
feat: throw when trying to use .value() on a method #2631
base: main
Are you sure you want to change the base?
Conversation
This prevents an error when running puppeteer/chrome on latest Ubuntu See: - https://github.com/sinonjs/sinon/actions/runs/12502499977/job/34881594651?pr=2631 - puppeteer/puppeteer#13365
@mantoni the errors seen in If you're seeing similar errors in Mochify, you might want to stick to |
|
||
if (propertyIsMethod) { | ||
throw new Error( | ||
`${rootStub.propName} is a function, not a getter or value. Use .returns() instead of .value()`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we supposed to allow setting .value()
on a getter property? Seems erronous.
it("allows stubbing getters", function () { | ||
const y = { | ||
get foo() { | ||
return "bar"; | ||
}, | ||
}; | ||
refute.exception(function () { | ||
createStub(y, "foo").value("bar"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original issue (#2629) does not deal with this issue, so this seems more like we are documenting existing (non-intentional) behavior? Dan does talk about getters, but that is the conventional Java-bean like getters, which are methods.
Purpose (TL;DR) - mandatory
This is a solution for #2629
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#get for the
.get
property on the property descriptor.How to verify - mandatory
npm install
npm test
Checklist for author
npm run lint
passes