Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Had so issue with jest react-native and bugsnag

I tried run Jest unit tests on React-Native with Bugsnag, but I got error:

 The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/en/configuration#testenvironment-string.
    Consider using the "jsdom" test environment.
    
    ReferenceError: window is not defined
      1 | import React from 'react';
    > 2 | import Bugsnag from '@bugsnag/react-native';
like image 268
Olexandr Akhtyrskyi Avatar asked Nov 25 '25 19:11

Olexandr Akhtyrskyi


2 Answers

Solution which is working for me:

we need to add mock bugsnag interceptor to jestSetupFile.js

jest.mock('@bugsnag/react-native', () => ({
  use(plugin) {
    const boundary = plugin.init();
    // we don't need the error boundary to swallow the errors, we want jest see them and fail the test
    delete boundary.prototype.componentDidCatch;
    return boundary;
  }
})); 
like image 144
Olexandr Akhtyrskyi Avatar answered Nov 27 '25 19:11

Olexandr Akhtyrskyi


I fixed it with just mocking Bugsnag: jest.mock("@bugsnag/react-native", () => jest.fn());

like image 22
Andrija Avatar answered Nov 27 '25 19:11

Andrija



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!