@@ -35,6 +35,20 @@ function Bam(): JSX.Element {
35
35
return < Boo title = { title } /> ;
36
36
}
37
37
38
+ function EffectSpyFallback ( { error } : { error : Error } ) : JSX . Element {
39
+ const [ counter , setCounter ] = useState ( 0 ) ;
40
+
41
+ React . useEffect ( ( ) => {
42
+ setCounter ( c => c + 1 ) ;
43
+ } , [ ] ) ;
44
+
45
+ return (
46
+ < span >
47
+ EffectSpyFallback { counter } - { error . message }
48
+ </ span >
49
+ ) ;
50
+ }
51
+
38
52
interface TestAppProps extends ErrorBoundaryProps {
39
53
errorComp ?: JSX . Element ;
40
54
}
@@ -101,7 +115,7 @@ describe('ErrorBoundary', () => {
101
115
it ( 'renders null if not given a valid `fallback` prop function' , ( ) => {
102
116
const { container } = render (
103
117
// @ts -expect-error Passing wrong type on purpose
104
- < ErrorBoundary fallback = { ( ) => 'Not a ReactElement' } >
118
+ < ErrorBoundary fallback = { ( ) => undefined } >
105
119
< Bam />
106
120
</ ErrorBoundary > ,
107
121
) ;
@@ -118,6 +132,15 @@ describe('ErrorBoundary', () => {
118
132
expect ( container . innerHTML ) . toBe ( '<h1>Error Component</h1>' ) ;
119
133
} ) ;
120
134
135
+ it ( 'renders a fallback that can use react hooks' , ( ) => {
136
+ const { container } = render (
137
+ < ErrorBoundary fallback = { EffectSpyFallback } >
138
+ < Bam />
139
+ </ ErrorBoundary > ,
140
+ ) ;
141
+ expect ( container . innerHTML ) . toBe ( '<span>EffectSpyFallback 1 - boom</span>' ) ;
142
+ } ) ;
143
+
121
144
it ( 'calls `onMount` when mounted' , ( ) => {
122
145
const mockOnMount = jest . fn ( ) ;
123
146
render (
0 commit comments