import React , { Suspense } from 'react' ; import { ErrorBoundary , FallbackProps } from 'react-error-boundary' ; import { RendererProps , WrapperComponent } from '../types/react' ; function createTestHarness < TProps , TResult > ( { callback , setValue , setError } , Wrapper ? , suspense = true ) { const TestComponent = ( { hookProps } ) => { setValue ( callback ( hookProps as TProps ) ) ; return null ; } ; let resetErrorBoundary = ( ) => { } ; const ErrorFallback = ( { error , resetErrorBoundary : reset } ) => { resetErrorBoundary = ( ) => { resetErrorBoundary = ( ) => { } ; reset ( ) ; } ; setError ( error ) ; return null ; } ; const testHarness = ( props ? ) => { resetErrorBoundary ( ) ; let component = < TestComponent hookProps = { props } />; if ( Wrapper ) { component = < Wrapper { ... ( props as TProps ) } > { component } < /Wrapper>; } if ( suspense ) { component = < Suspense fallback = { null } > { component } < /Suspense>; } return < ErrorBoundary FallbackComponent = { ErrorFallback } > { component } < /ErrorBoundary>; } ; return testHarness ; } export { createTestHarness } ;