如何为react应用程序模拟Bugstuck的测试用例


Bugsnag.start({
apiKey: BUGSNAG_KEY,
plugins: [new BugsnagPluginReact()],
releaseStage: process.env.NODE_ENV,
appVersion: APP_VERSION,
})
const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React)

使用"@bugstang/js":"7.11.0"bugstang/plugin-react":"7.11.0";,

尝试执行jost.mock("@bugstang/js"(,但出现错误TypeError:无法读取未定义的属性"createErrorBoundary">

以下是如何使其工作的示例:

jest.mock('bugsnag-js', () => (
() => ({
use(plugin) {
const boundary = plugin.init();
/* you don't want the error boundary to swallow the errors, 
just want jest to see them and fail the test
*/
delete boundary.prototype.componentDidCatch;
return boundary;
},
})
));

最新更新