我尝试使用 Bugsnag 在 React-Native 上运行 Jest 单元测试,但出现错误:
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';
最佳答案
对我有用的解决方案:
我们需要将模拟 bugsnag 拦截器添加到 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;
}
}));
关于react-native - jest react-native 和 bugsnag 有这样的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66173565/