Skip to content

renderHook's rerender not has undefined prop type unless explicitly typed #1420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rarenatoe opened this issue Jun 20, 2023 · 1 comment · Fixed by #1421
Closed

renderHook's rerender not has undefined prop type unless explicitly typed #1420

rarenatoe opened this issue Jun 20, 2023 · 1 comment · Fixed by #1421

Comments

@rarenatoe
Copy link

Describe the bug

The following code returns a typescript error

import { renderHook } from '@testing-library/react-native'
import { useMyHook } from '../hooks'

describe('useMyHook', () => {
  it('should pass', () => {
    const { result, rerender } = renderHook((num: number) => useMyHook(num), { initialProps: undefined })

    expect(result.current).toBeUndefined()

    rerender('granted') //Error here, props type is undefined

    expect(result.current).toBe('granted')
  })
})

For it to work fine I have to to do

    const { result, rerender } = renderHook<number, number>((num: number) => useMyHook(num), { initialProps: undefined })

this doesn't happen when using

import { renderHook } from '@testing-library/react-hooks'

Expected behavior

Not having a typescript error and instead pull the prop types correctly.

Steps to Reproduce

See description.

Screenshots

Screenshot 2023-06-20 at 12 58 02 Screenshot 2023-06-20 at 12 58 17

Versions

  npmPackages:
    @testing-library/react-native: 12.1.2 => 12.1.2 
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.9 => 0.70.9 
    react-test-renderer: 18.1.0 => 18.1.0 
@pierrezimmermannbam
Copy link
Collaborator

Hello @rarenatoe, thanks for submitting the issue! I have opened a pr #1421 to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants