【问题标题】:How to trigger an uncaught exception in React, for Sentry testing?如何在 React 中触发未捕获的异常以进行 Sentry 测试?
【发布时间】:2020-12-07 10:37:28
【问题描述】:

我需要在 React 应用程序中触发错误,以确保我的 Sentry.io 已正确配置。

这是 Sentry 文档要求我执行的操作:

You can trigger your first event from your development 
environment by raising an exception somewhere within 
your application. An example of this would be rendering 
a button whose onClick handler attempts to invoke a method 
that does not exist:

return <button onClick={methodDoesNotExist}>Break the world</button>;

但是,即使我为文件禁用了 eslint,React 本身也不会让我定义 onClickundefined 方法的元素。

我怎么会产生这样的错误?

【问题讨论】:

  • 你不能在某个地方throw 'Oh no an error' 吗?
  • 谢谢你这工作完美,我应该想到它哈哈。

标签: reactjs sentry


【解决方案1】:

只需添加:

<button onClick={()=>{
throw 'oh no an error'`
}}> Err </button>

感谢@omnikron

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多