Failed to get mock metadata: node_modules/@sentry/react/cjs/index.js
See original GitHub issueIs there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
SDK Version
7.16.0
Framework Version
React 18.2.0
Link to Sentry event
No response
Steps to Reproduce
- Write a Jest test with the following contents:
import { init } from '@sentry/react';
jest.mock('@sentry/react');
Expected Result
No error
Actual Result
Test fails with Failed to get mock metadata: node_modules/@sentry/react/cjs/index.js
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Jest issue - ReactElement.js: Failed to get mock metadata
Try to disable mocking for react - in your jset configuraction in package.json: "unmockedModulePathPatterns": [ "<rootDir>/node_modules/react", ...
Read more >Manual Mocks - Jest
Manual mocks are used to stub out functionality with mock data. ... a file called user.js and put it in the models/__mocks__ directory....
Read more >Mocking Sentry in Jest and Gatsby - Bored Hacking
This is a very short and simple tutorial describing how to mock Sentry in the Jest testing framework and more specifically in a...
Read more >The only 3 steps you need to mock an API call in Jest
I recently found myself working in a Javascript codebase where I needed to implement new Jest tests. I knew very little at the...
Read more >azu on Twitter: "これっぽいエラーがでてる "[jest-12.x.x] Failed ...
これっぽいエラーがでてる "[jest-12.x.x] Failed to get mock metadata: core-js · Issue #966 · facebook/jest". Translate Tweet.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This will be fixed in the SDK with the next release - we recognize that not everyone can bump jest versions, but do want to shout out @Tofandel for fixing this in jest directly!
Appreciate the patience everyone!
The temp fix here for everyone is to actually add mocks for your method, similar to what is done here: https://github.com/getsentry/sentry-javascript/pull/5951/files#diff-9b6a20828c3c1c7a7e897abb6d7c8a88130fc3ac55dad3cbd8d3ac92aff19fadR9
Probably also cleaner because you can control exactly what is being mocked, but that’s probably a matter of opinion on coding style.