File tree 1 file changed +59
-0
lines changed
packages/react-reconciler/src/__tests__
1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails react-core
8
+ * @jest -environment node
9
+ */
10
+
11
+ 'use strict' ;
12
+
13
+ let React ;
14
+ let ReactNoop ;
15
+
16
+ describe ( 'ReactIncrementalErrorReplay' , ( ) => {
17
+ beforeEach ( ( ) => {
18
+ jest . resetModules ( ) ;
19
+ React = require ( 'react' ) ;
20
+ ReactNoop = require ( 'react-noop-renderer' ) ;
21
+ } ) ;
22
+
23
+ function div ( ...children ) {
24
+ children = children . map ( c => ( typeof c === 'string' ? { text : c } : c ) ) ;
25
+ return { type : 'div' , children, prop : undefined } ;
26
+ }
27
+
28
+ function span ( prop ) {
29
+ return { type : 'span' , children : [ ] , prop} ;
30
+ }
31
+
32
+ it ( 'should fail gracefully on error in the host environment' , ( ) => {
33
+ ReactNoop . simulateErrorInHostConfig ( ( ) => {
34
+ ReactNoop . render ( < span /> ) ;
35
+ expect ( ( ) => ReactNoop . flush ( ) ) . toThrow ( 'Error in host config.' ) ;
36
+ } ) ;
37
+ } ) ;
38
+
39
+ it ( 'should fail gracefully on error that does not reproduce on replay' , ( ) => {
40
+ let didInit = false ;
41
+
42
+ function badLazyInit ( ) {
43
+ const needsInit = ! didInit ;
44
+ didInit = true ;
45
+ if ( needsInit ) {
46
+ throw new Error ( 'Hi' ) ;
47
+ }
48
+ }
49
+
50
+ class App extends React . Component {
51
+ render ( ) {
52
+ badLazyInit ( ) ;
53
+ return < div /> ;
54
+ }
55
+ }
56
+ ReactNoop . render ( < App /> ) ;
57
+ expect ( ( ) => ReactNoop . flush ( ) ) . toThrow ( 'Hi' ) ;
58
+ } ) ;
59
+ } ) ;
You can’t perform that action at this time.
0 commit comments