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

feat: throw when trying to use .value() on a method #2631

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mroderick
Copy link
Member

@mroderick mroderick commented Dec 26, 2024

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

  1. Check out this branch
  2. npm install
  3. npm test

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

@mroderick mroderick added the semver:major changes will cause a new major version label Dec 26, 2024
@mroderick mroderick requested a review from fatso83 December 26, 2024 09:59
@mroderick
Copy link
Member Author

@mantoni the errors seen in ubuntu-latest might also affect Mochify running on latest Chrome + Ubuntu.

image

If you're seeing similar errors in Mochify, you might want to stick to ubuntu-22.04 for a bit, while the Chrome/Ubuntu conflict gets fixed in Ubuntu/Puppeteer/Chrome land.


if (propertyIsMethod) {
throw new Error(
`${rootStub.propName} is a function, not a getter or value. Use .returns() instead of .value()`,
Copy link
Contributor

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.

Comment on lines +3784 to +3793
it("allows stubbing getters", function () {
const y = {
get foo() {
return "bar";
},
};
refute.exception(function () {
createStub(y, "foo").value("bar");
});
});
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:major changes will cause a new major version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants