File tree 1 file changed +60
-0
lines changed
packages/react-reconciler/src/__tests__
1 file changed +60
-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 ReactFeatureFlags ;
14
+ let React ;
15
+ let ReactNoop ;
16
+
17
+ describe ( 'ReactIncrementalErrorReplay' , ( ) => {
18
+ beforeEach ( ( ) => {
19
+ jest . resetModules ( ) ;
20
+ React = require ( 'react' ) ;
21
+ ReactNoop = require ( 'react-noop-renderer' ) ;
22
+ } ) ;
23
+
24
+ function div ( ...children ) {
25
+ children = children . map ( c => ( typeof c === 'string' ? { text : c } : c ) ) ;
26
+ return { type : 'div' , children, prop : undefined } ;
27
+ }
28
+
29
+ function span ( prop ) {
30
+ return { type : 'span' , children : [ ] , prop} ;
31
+ }
32
+
33
+ it ( 'should fail gracefully on error in the host environment' , ( ) => {
34
+ ReactNoop . simulateErrorInHostConfig ( ( ) => {
35
+ ReactNoop . render ( < span /> ) ;
36
+ expect ( ( ) => ReactNoop . flush ( ) ) . toThrow ( 'Error in host config.' ) ;
37
+ } ) ;
38
+ } ) ;
39
+
40
+ it ( 'should fail gracefully on error that does not reproduce on replay' , ( ) => {
41
+ let index = 0 ;
42
+
43
+ class App extends React . Component {
44
+ render ( ) {
45
+ if ( index === 0 ) {
46
+ index ++ ;
47
+ throw new Error ( 'Hi' ) ;
48
+ }
49
+
50
+ return (
51
+ < div >
52
+ < h1 > Hello, { this . props . name } </ h1 >
53
+ </ div >
54
+ ) ;
55
+ }
56
+ }
57
+ ReactNoop . render ( < App /> ) ;
58
+ expect ( ( ) => ReactNoop . flush ( ) ) . toThrow ( 'Hi' ) ;
59
+ } ) ;
60
+ } ) ;
You can’t perform that action at this time.
0 commit comments