From 43793a10c2636cf0f14cdb8e14f7374facb9422d Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 2 Aug 2017 21:29:54 +0530 Subject: [PATCH] Add test case that demonstrates errors are logged even if they're caught --- .../fixtures/error-handling/index.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/fixtures/dom/src/components/fixtures/error-handling/index.js b/fixtures/dom/src/components/fixtures/error-handling/index.js index b73be12910018..c2465592864ac 100644 --- a/fixtures/dom/src/components/fixtures/error-handling/index.js +++ b/fixtures/dom/src/components/fixtures/error-handling/index.js @@ -1,4 +1,5 @@ const React = window.React; +const ReactDOM = window.ReactDOM; import FixtureSet from '../../FixtureSet'; import TestCase from '../../TestCase'; @@ -56,6 +57,34 @@ class Example extends React.Component { } } +class TriggerErrorAndCatch extends React.Component { + container = document.createElement('div'); + + triggerErrorAndCatch = () => { + // Use setImmediate so that the render is syncrhonous + setImmediate(() => { + try { + ReactDOM.render( + { + throw new Error('Caught error'); + }} + />, + this.container, + ); + } catch (e) {} + }); + }; + + render() { + return ( + + ); + } +} + export default class ErrorHandlingTestCases extends React.Component { render() { return ( @@ -119,6 +148,17 @@ export default class ErrorHandlingTestCases extends React.Component { }} /> + + +
  • Click the "Trigger render error and catch" button
  • +
    + + Open the console. "Uncaught Error: Caught error" should have been logged by the browser. + + +
    ); }