gpt4 book ai didi

react-native - jest react-native 和 bugsnag 有这样的问题

转载 作者:行者123 更新时间:2023-12-05 03:45:02 24 4
gpt4 key购买 nike

我尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com