@@ -54,6 +54,7 @@ export default function describeCDC({
54
54
}
55
55
56
56
render ( ) {
57
+ const { ThrowerComponent } = this . props ;
57
58
const {
58
59
didThrow,
59
60
throws,
@@ -62,7 +63,7 @@ export default function describeCDC({
62
63
< div >
63
64
< MaybeFragment >
64
65
< span >
65
- < Thrower throws = { throws } />
66
+ { < ThrowerComponent throws = { throws } /> }
66
67
< div >
67
68
{ didThrow ? 'HasThrown' : 'HasNotThrown' }
68
69
</ div >
@@ -73,6 +74,10 @@ export default function describeCDC({
73
74
}
74
75
}
75
76
77
+ ErrorBoundary . defaultProps = {
78
+ ThrowerComponent : Thrower ,
79
+ } ;
80
+
76
81
function ErrorSFC ( props ) {
77
82
return < ErrorBoundary { ...props } /> ;
78
83
}
@@ -121,6 +126,39 @@ export default function describeCDC({
121
126
} ) ;
122
127
} ) ;
123
128
129
+ itIf (
130
+ is ( '>= 16.6' ) ,
131
+ 'catches a simulated error on memo() component' ,
132
+ ( ) => {
133
+ const MemoThrower = React . memo ( Thrower ) ;
134
+ const spy = sinon . spy ( ) ;
135
+ const wrapper = Wrap (
136
+ < ErrorBoundary spy = { spy } ThrowerComponent = { MemoThrower } /> ,
137
+ ) ;
138
+
139
+ expect ( spy ) . to . have . property ( 'callCount' , 0 ) ;
140
+
141
+ expect ( ( ) => wrapper . find ( Thrower ) . simulateError ( errorToThrow ) ) . not . to . throw ( ) ;
142
+
143
+ expect ( spy ) . to . have . property ( 'callCount' , 1 ) ;
144
+
145
+ expect ( spy . args ) . to . be . an ( 'array' ) . and . have . lengthOf ( 1 ) ;
146
+ const [ [ actualError , info ] ] = spy . args ;
147
+ expect ( ( ) => {
148
+ throw actualError ;
149
+ } ) . to . throw ( errorToThrow ) ;
150
+ expect ( info ) . to . deep . equal ( {
151
+ componentStack : `
152
+ in Memo(Thrower) (created by ErrorBoundary)
153
+ in span (created by ErrorBoundary)${ hasFragments ? '' : `
154
+ in main (created by ErrorBoundary)` }
155
+ in div (created by ErrorBoundary)
156
+ in ErrorBoundary (created by WrapperComponent)
157
+ in WrapperComponent` ,
158
+ } ) ;
159
+ } ,
160
+ ) ;
161
+
124
162
it ( 'rerenders on a simulated error' , ( ) => {
125
163
const wrapper = Wrap ( < ErrorBoundary spy = { sinon . stub ( ) } /> ) ;
126
164
0 commit comments