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
[0.18.1] TypeError: Symbol.hasInstance is read-only #1671
Comments
I've just come across this issue with my mocks, too. Locked in my project to 0.18.0 for now |
@simon-abbott do you have any ideas on how to fix this? |
Reproduced it with 0.19.1. vi.mock('something', async () => ({
// @ts-ignore for mocking
...(await vi.importActual('something')),
})) Edit: |
Please, don't post comments like "still not working". When someone will work on a fix, it will be displayed here. |
When the vitest/packages/vitest/src/runtime/mocker.ts Lines 213 to 217 in 57c2367
|
Hmm. I know roughly what is causing this, but I'll need a little bit of time to be able to fix it. I'll try to take a look this evening. |
…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
…-dev#1671) Sometimes while automocking we will encounter a property that, for some unknown reason, throws an error when you try to define it. Unfortunately I can't figure out _why_ it errors, so instead I have opted to quietly skip these unsettable properties. If that becomes a problem in the future this can be revisited, but I don't forsee it being an issue since these keys are mostly deeply internal prototype stuff that 99.999% of people don't even know exists, let alone want to mock. Plus, if you _really_ need to have this behavior you can always use `__mocks__` or just shim it inline yourself.
Figured out a fix! #1786. |
Describe the bug
My tests that use
vi.mock
(in this case, mocking out theora
module) started failing as of vitest v0.18.1 with the following error:In the reproduction (below), it presents itself as simply:
TypeError: Symbol.hasInstance is read-only
I'm assuming this is related to PR #1648 but I'm not sure if I need to update my usage to comply with the intent of the PR or what.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-ht4a9x?file=test/mock.test.ts&view=editor
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: