Skip to content

Commit

Permalink
fix: Type for options in autodetected renderer was incorrectly inferr…
Browse files Browse the repository at this point in the history
…ing 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.
  • Loading branch information
mpeyper committed Jan 8, 2021
1 parent f6096ba commit 4786242
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion 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' },
Expand Down
11 changes: 0 additions & 11 deletions src/types/index.ts
Expand Up @@ -47,17 +47,6 @@ export type RenderHook<
Omit<TRenderer, keyof Renderer<TProps>> &
AsyncUtils

export interface ReactHooksRenderer {
renderHook: <TProps, TResult, TOptions>(
callback: (props: TProps) => TResult,
options?: RenderHookOptions<TProps, TOptions>
) => RenderHook<TProps, TResult>
act: Act
cleanup: () => void
addCleanup: (callback: () => Promise<void> | void) => () => void
removeCleanup: (callback: () => Promise<void> | void) => void
}

export type RenderHookOptions<TProps, TOptions extends {}> = TOptions & {
initialProps?: TProps
}
Expand Down
13 changes: 13 additions & 0 deletions src/types/react.ts
@@ -1,7 +1,20 @@
import { ComponentType } from 'react'

import { RenderHook, RenderHookOptions, Act } from '.'

export type WrapperComponent<TProps> = ComponentType<TProps>

export type RendererOptions<TProps> = {
wrapper?: WrapperComponent<TProps>
}

export interface ReactHooksRenderer {
renderHook: <TProps, TResult>(
callback: (props: TProps) => TResult,
options?: RenderHookOptions<TProps, RendererOptions<TProps>>
) => RenderHook<TProps, TResult>
act: Act
cleanup: () => void
addCleanup: (callback: () => Promise<void> | void) => () => void
removeCleanup: (callback: () => Promise<void> | void) => void
}
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down

0 comments on commit 4786242

Please sign in to comment.