Skip to content
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

react-native-sentry is missing interfaces when running under jest #455

Closed
2 tasks
wontonst opened this issue Aug 3, 2018 · 2 comments
Closed
2 tasks

react-native-sentry is missing interfaces when running under jest #455

wontonst opened this issue Aug 3, 2018 · 2 comments

Comments

@wontonst
Copy link

wontonst commented Aug 3, 2018

OS:

  • Windows
  • [ X ] MacOS
  • Linux

Platform:

  • [ X ] iOS
  • [ X ] Android

Output of node -v && npm -v && npm ls --prod --depth=0

v9.3.0
6.2.0

Config:

Sentry.config("https://...@sentry.io/...").install()

I have following issue:

I am testing that my root component works.

  const rendered = renderer.create(<App />).toJSON();
  expect(rendered).toBeTruthy();

In my App.js, I install sentry and call Sentry.setTagsContext. When running unit tests, the mock that comes with react-native-sentry is lacking some of the interfaces in production, i.e..

console.log(Sentry);
    { clearContext: [Function: clearContext],
      setUserContext: [Function: setUserContext],
      config: [Function: config],
      captureMessage: [Function: captureMessage] }

Same result on both react-native-sentry v 0.37.1 and 0.38.3

Jest 23.4.1

Steps to reproduce:

  • Add a call to Sentry.setTagsContext in your root component
  • Create a jest test where you import and render the root component

Actual result:
TypeError: _reactNativeSentry.Sentry.setTagsContext is not a function

Expected result:
Test calls mock setTagsContext and continues with test

@HazAT
Copy link
Member

HazAT commented Sep 4, 2019

I am closing all old issues, please if this is still a problem feel free to revive it.
Also, consider moving to our new SDK @sentry/react-native if it still happens there please open a new issue.

@HazAT HazAT closed this as completed Sep 4, 2019
@markgibaud
Copy link

In your jestSetup.js:

jest.mock('react-native-sentry', () => ({
  Sentry: {
    setTagsContext: jest.fn(),
    setExtraContext: jest.fn(),
    captureBreadcrumb: jest.fn()
  }
}));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants