Skip to content

Commit 4ead36f

Browse files
committed
Refactor TestHook catch to not disable lint rules
1 parent 900e89c commit 4ead36f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/pure.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { act, create, ReactTestRenderer } from 'react-test-renderer'
33
import asyncUtils from './asyncUtils'
44
import { cleanup, addCleanup, removeCleanup } from './cleanup'
55

6+
function isPromise<T>(value: unknown): boolean {
7+
return typeof (value as PromiseLike<T>).then === 'function'
8+
}
9+
610
type TestHookProps<TProps, TResult> = {
711
callback: (props: TProps) => TResult
812
hookProps: TProps | undefined
913
onError: (error: Error) => void
1014
children: (value: TResult) => void
1115
}
16+
1217
function TestHook<TProps, TResult>({
1318
callback,
1419
hookProps,
@@ -18,13 +23,11 @@ function TestHook<TProps, TResult>({
1823
try {
1924
// coerce undefined into TProps, so it maintains the previous behaviour
2025
children(callback(hookProps as TProps))
21-
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
22-
} catch (err) {
23-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
24-
if (err.then) {
26+
} catch (err: unknown) {
27+
if (isPromise(err)) {
2528
throw err
2629
} else {
27-
onError(err)
30+
onError(err as Error)
2831
}
2932
}
3033
return null

0 commit comments

Comments
 (0)