SpyOn captureException no longer works in sentry/react 8
Environment
SaaS (https://sentry.io/)
Steps to Reproduce
const captureExceptionSpy = vi.spyOn(Sentry, 'captureException');
Expected Result
Works fine
Actual Result
TypeError: Cannot redefine property: captureException
Product Area
Unknown
Link
No response
DSN
No response
Version
8.10.0
Assigning to @getsentry/support for routing ⏲️
Hi @mikecousins thanks for writing in. I think vitest is using the ESM build of the SDK here (because we are finally publishing them properly). This means that you are running into the fact that ESM modules are immutable (by the spec itself), so you can't rebind them via vi.spyOn.
I recommend using vi.mock instead. Docs here. This is a safer pattern that will work with all ESM libraries.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀