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';
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;
}
}));
I fixed it with just mocking Bugsnag: jest.mock("@bugsnag/react-native", () => jest.fn());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With