File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
packages/react/src/__tests__ Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,40 @@ describe('Profiler', () => {
173173 loadModules ( { enableSchedulerTracking} ) ;
174174 } ) ;
175175
176+ it ( 'should handle errors thrown' , ( ) => {
177+ const callback = jest . fn ( id => {
178+ if ( id === 'throw' ) {
179+ throw Error ( 'expected' ) ;
180+ }
181+ } ) ;
182+
183+ let didMount = false ;
184+ class ClassComponent extends React . Component {
185+ componentDidMount ( ) {
186+ didMount = true ;
187+ }
188+ render ( ) {
189+ return this . props . children ;
190+ }
191+ }
192+
193+ // Errors thrown from onRender should not break the commit phase,
194+ // Or prevent other lifecycles from being called.
195+ expect ( ( ) =>
196+ ReactTestRenderer . create (
197+ < ClassComponent >
198+ < React . unstable_Profiler id = "do-not-throw" onRender = { callback } >
199+ < React . unstable_Profiler id = "throw" onRender = { callback } >
200+ < div />
201+ </ React . unstable_Profiler >
202+ </ React . unstable_Profiler >
203+ </ ClassComponent > ,
204+ ) ,
205+ ) . toThrow ( 'expected' ) ;
206+ expect ( didMount ) . toBe ( true ) ;
207+ expect ( callback ) . toHaveBeenCalledTimes ( 2 ) ;
208+ } ) ;
209+
176210 it ( 'is not invoked until the commit phase' , ( ) => {
177211 const callback = jest . fn ( ) ;
178212
You can’t perform that action at this time.
0 commit comments