如何在 React 中触发未捕获的异常以进行哨兵测试?
How to trigger an uncaught exception in React, for Sentry testing?
我需要在 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 本身也不会让我定义一个 onClick
是 undefined
方法的元素。
我还能如何产生这样的错误?
只需添加:
<button onClick={()=>{
throw 'oh no an error'`
}}> Err </button>
感谢@omnikron
我需要在 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 本身也不会让我定义一个 onClick
是 undefined
方法的元素。
我还能如何产生这样的错误?
只需添加:
<button onClick={()=>{
throw 'oh no an error'`
}}> Err </button>
感谢@omnikron