From 4786242a9a22c6f235f537d26b9990c2bec4b24d Mon Sep 17 00:00:00 2001 From: Michael Peyper Date: Fri, 8 Jan 2021 20:24:47 +1100 Subject: [PATCH] fix: Type for options in autodetected renderer was incorrectly inferring any passed type (#527) Changed `renderHook` in `ReactHooksRenderer` type to not use a generic for options but rather the react specific `RendererOptions`. Moved `ReactHooksRenderer` into react specific types as all auto-detected renders are react renderers. All modules are currently exporting both the shared types and the react types so this a non-breaking change. --- src/pure.ts | 2 +- src/types/index.ts | 11 ----------- src/types/react.ts | 13 +++++++++++++ test/dom/autoCleanup.disabled.ts | 2 +- test/dom/autoCleanup.noAfterEach.ts | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/pure.ts b/src/pure.ts index 56b3cebe..d19cd1a7 100644 --- a/src/pure.ts +++ b/src/pure.ts @@ -1,4 +1,4 @@ -import { ReactHooksRenderer } from './types' +import { ReactHooksRenderer } from './types/react' const renderers = [ { required: 'react-test-renderer', renderer: './native/pure' }, diff --git a/src/types/index.ts b/src/types/index.ts index d9fce828..8918c2ca 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -47,17 +47,6 @@ export type RenderHook< Omit> & AsyncUtils -export interface ReactHooksRenderer { - renderHook: ( - callback: (props: TProps) => TResult, - options?: RenderHookOptions - ) => RenderHook - act: Act - cleanup: () => void - addCleanup: (callback: () => Promise | void) => () => void - removeCleanup: (callback: () => Promise | void) => void -} - export type RenderHookOptions = TOptions & { initialProps?: TProps } diff --git a/src/types/react.ts b/src/types/react.ts index 09923286..dbaa16ed 100644 --- a/src/types/react.ts +++ b/src/types/react.ts @@ -1,7 +1,20 @@ import { ComponentType } from 'react' +import { RenderHook, RenderHookOptions, Act } from '.' + export type WrapperComponent = ComponentType export type RendererOptions = { wrapper?: WrapperComponent } + +export interface ReactHooksRenderer { + renderHook: ( + callback: (props: TProps) => TResult, + options?: RenderHookOptions> + ) => RenderHook + act: Act + cleanup: () => void + addCleanup: (callback: () => Promise | void) => () => void + removeCleanup: (callback: () => Promise | void) => void +} diff --git a/test/dom/autoCleanup.disabled.ts b/test/dom/autoCleanup.disabled.ts index 2c797345..1bcf45be 100644 --- a/test/dom/autoCleanup.disabled.ts +++ b/test/dom/autoCleanup.disabled.ts @@ -1,6 +1,6 @@ import { useEffect } from 'react' -import { ReactHooksRenderer } from 'types' +import { ReactHooksRenderer } from 'types/react' // This verifies that if RHTL_SKIP_AUTO_CLEANUP is set // then we DON'T auto-wire up the afterEach for folks diff --git a/test/dom/autoCleanup.noAfterEach.ts b/test/dom/autoCleanup.noAfterEach.ts index 1c0821b4..12dd75e1 100644 --- a/test/dom/autoCleanup.noAfterEach.ts +++ b/test/dom/autoCleanup.noAfterEach.ts @@ -1,6 +1,6 @@ import { useEffect } from 'react' -import { ReactHooksRenderer } from 'types' +import { ReactHooksRenderer } from 'types/react' // This verifies that if RHTL_SKIP_AUTO_CLEANUP is set // then we DON'T auto-wire up the afterEach for folks