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

fix: auto-mock based on descriptor list, not property keys (fix #1671) #1782

Closed

Conversation

simon-abbott
Copy link
Contributor

These two methods seem like they should be the same, but they're not. Some objects, especially native Node exports, behave strangely; they have properties that are enumerated by Object.getOwnPropertyNames() and/or Object.getOwnPropertySymbols(), but when you try to get the descriptor for that property using Object.getOwnPropertyDescriptor() it returns undefined. To combat this, instead of getting the property names / symbols manually, we instead offload that work to the JS engine itself via Object.getOwnPropertyDescriptors, and just iterate through the result.

Fixes #1671

…t-dev#1671)

These two methods seem like they should be the same, but they're not.
Some objects, especially native Node exports, behave strangely; they
have properties that are enumerated by `Object.getOwnPropertyNames()`
and/or `Object.getOwnPropertySymbols()`, but when you try to get the
descriptor for that property using `Object.getOwnPropertyDescriptor()`
it returns `undefined`. To combat this, instead of getting the property
names / symbols manually, we instead offload that work to the JS engine
itself via `Object.getOwnPropertyDescriptors`, and just iterate through
the result.

Fixes vitest-dev#1671
@simon-abbott
Copy link
Contributor Author

Hmm... That didn't seem to work quite as smoothly as I'd hoped... Back to the drawing board I guess!

@simon-abbott simon-abbott marked this pull request as draft August 4, 2022 04:40
@simon-abbott
Copy link
Contributor Author

Closed in favor of #1786.

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

Successfully merging this pull request may close these issues.

[0.18.1] TypeError: Symbol.hasInstance is read-only
1 participant