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.

Failed to get mock metadata: node_modules/@sentry/react/cjs/index.js

See original GitHub issue

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/react

SDK Version

7.16.0

Framework Version

React 18.2.0

Link to Sentry event

No response

Steps to Reproduce

  1. 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
AbhiPrasadcommented, Oct 27, 2022

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!

4reactions
AbhiPrasadcommented, Oct 19, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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