@@ -168,37 +168,21 @@ function getAdvancedFakeReport(isArchived, isUserCreatedPolicyRoom, hasAddWorksp
168
168
* @param {String } [currentReportID]
169
169
*/
170
170
function getDefaultRenderedSidebarLinks ( currentReportID = '' ) {
171
- // An ErrorBoundary needs to be added to the rendering so that any errors that happen while the component
172
- // renders are logged to the console. Without an error boundary, Jest only reports the error like "The above error
173
- // occurred in your component", except, there is no "above error". It's just swallowed up by Jest somewhere.
174
- // With the ErrorBoundary, those errors are caught and logged to the console so you can find exactly which error
175
- // might be causing a rendering issue when developing tests.
176
- class ErrorBoundary extends React . Component {
177
- // Error boundaries have to implement this method. It's for providing a fallback UI, but
178
- // we don't need that for unit testing, so this is basically a no-op.
179
- static getDerivedStateFromError ( error ) {
180
- return { error} ;
181
- }
171
+ // A try-catch block needs to be added to the rendering so that any errors that happen while the component
172
+ // renders are caught and logged to the console. Without the try-catch block, Jest might only report the error
173
+ // as "The above error occurred in your component", without providing specific details. By using a try-catch block,
174
+ // any errors are caught and logged, allowing you to identify the exact error that might be causing a rendering issue
175
+ // when developing tests.
182
176
183
- componentDidCatch ( error , errorInfo ) {
184
- console . error ( error , errorInfo ) ;
185
- }
186
-
187
- render ( ) {
188
- // eslint-disable-next-line react/prop-types
189
- return this . props . children ;
190
- }
177
+ try {
178
+ // Wrap the SideBarLinks inside of LocaleContextProvider so that all the locale props
179
+ // are passed to the component. If this is not done, then all the locale props are missing
180
+ // and there are a lot of render warnings. It needs to be done like this because normally in
181
+ // our app (App.js) is when the react application is wrapped in the context providers
182
+ render ( < MockedSidebarLinks currentReportID = { currentReportID } /> ) ;
183
+ } catch ( error ) {
184
+ console . error ( error ) ;
191
185
}
192
-
193
- // Wrap the SideBarLinks inside of LocaleContextProvider so that all the locale props
194
- // are passed to the component. If this is not done, then all the locale props are missing
195
- // and there are a lot of render warnings. It needs to be done like this because normally in
196
- // our app (App.js) is when the react application is wrapped in the context providers
197
- render (
198
- < ErrorBoundary >
199
- < MockedSidebarLinks currentReportID = { currentReportID } />
200
- </ ErrorBoundary > ,
201
- ) ;
202
186
}
203
187
204
188
/**
0 commit comments