Skip to content

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.

Copy link
Member Author

@mroderick mroderick Jan 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure either ... to me it seemed more reasonable to use .returns() rather than .value() on a getter. I'm happy to change it to do that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just do the simplest thing: prevent using value() on a method. So "${rootStub.propName} is a function and should not be overridden by .value(). Use .returns() when creating a function that returns a value.

There is little reason to add synthetic property getters and setters to the mix, as it just adds more noise/possible confusion, IMHO.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change it like in #2631 (comment), then this test will obviously also need to be changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stalled for a year. Do whatever needs to be done and get a new breaking change for 2026 🎉?

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

3 participants