File tree 1 file changed +40
-0
lines changed
fixtures/dom/src/components/fixtures/error-handling
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1
1
const React = window . React ;
2
+ const ReactDOM = window . ReactDOM ;
2
3
3
4
import FixtureSet from '../../FixtureSet' ;
4
5
import TestCase from '../../TestCase' ;
@@ -56,6 +57,34 @@ class Example extends React.Component {
56
57
}
57
58
}
58
59
60
+ class TriggerErrorAndCatch extends React . Component {
61
+ container = document . createElement ( 'div' ) ;
62
+
63
+ triggerErrorAndCatch = ( ) => {
64
+ // Use setImmediate so that the render is syncrhonous
65
+ setImmediate ( ( ) => {
66
+ try {
67
+ ReactDOM . render (
68
+ < BadRender
69
+ throws = { ( ) => {
70
+ throw new Error ( 'Caught error' ) ;
71
+ } }
72
+ /> ,
73
+ this . container
74
+ ) ;
75
+ } catch ( e ) { }
76
+ } ) ;
77
+ } ;
78
+
79
+ render ( ) {
80
+ return (
81
+ < button onClick = { this . triggerErrorAndCatch } >
82
+ Trigger error and catch
83
+ </ button >
84
+ ) ;
85
+ }
86
+ }
87
+
59
88
export default class ErrorHandlingTestCases extends React . Component {
60
89
render ( ) {
61
90
return (
@@ -119,6 +148,17 @@ export default class ErrorHandlingTestCases extends React.Component {
119
148
} }
120
149
/>
121
150
</ TestCase >
151
+ < TestCase
152
+ title = "Errors are logged even if they're caught (development mode only)"
153
+ description = "" >
154
+ < TestCase . Steps >
155
+ < li > Click the "Trigger render error and catch" button</ li >
156
+ </ TestCase . Steps >
157
+ < TestCase . ExpectedResult >
158
+ Open the console. "Uncaught Error: Caught error" should have been logged by the browser.
159
+ </ TestCase . ExpectedResult >
160
+ < TriggerErrorAndCatch />
161
+ </ TestCase >
122
162
</ FixtureSet >
123
163
) ;
124
164
}
You can’t perform that action at this time.
0 commit comments