question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Describe the bug

My tests that use vi.mock (in this case, mocking out the ora module) started failing as of vitest v0.18.1 with the following error:

TypeError: Cannot assign to read only property 'Symbol(Symbol.hasInstance)' of function 'function(...o) {
    if (e.called = !0, e.callCount++, e.calls.push(o), e.next) {
      let [s, l] = e.next;
  ...<omitted>... }'

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

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 17.74 GB / 31.92 GB
  Binaries:
    Node: 16.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.12.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 103.0.5060.114
    Edge: Spartan (44.19041.1266.0), Chromium (103.0.1264.62)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    vitest: 0.18.1 => 0.18.1

Used Package Manager

npm

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:9
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sheremet-vacommented, Jul 26, 2022

Please, don’t post comments like “still not working”. When someone will work on a fix, it will be displayed here.

0reactions
simon-abbottcommented, Aug 4, 2022

Figured out a fix! #1786.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Symbol.hasInstance - JavaScript - MDN Web Docs
The Symbol.hasInstance well-known symbol is used to determine if a constructor object recognizes an object as its instance.
Read more >
Why can I not assign Symbol.hasInstance onto a function?
The reason is because the property descriptor for Function.prototype[Symbol.hasInstance] has {writable: false} , which makes it not possible ...
Read more >
Raw file - Public Repositories - IBS Bitbucket
moveStart('character', pos);\n range.select();\n }\n}\n\nvar ... _pluginName = toUpperCaseFirst(pluginName);\n\n if (!registeredPlugins.has(instance) || !
Read more >
Untitled
undefined":r(i)))throw new TypeError(i+"must be non-object");for(var o in i)n(i ... W+a.F*!L,{Symbol:A});for(var te="hasInstance,isConcatSpreadable,iterator ...
Read more >
Customizing ES6 via well-known symbols - 2ality
In ECMAScript 6, the object Symbol has several properties that contain ... obj.prop = 456; // TypeError: Cannot assign to read-only property.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found