Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

renderHook (and rerender) doesn't properly infer overload type when using initialProps. #822

Open
Labels
bugSomething isn't working
@rnarcos

Description

  • @react-testing-library/react version (if applicable): 12.1.2
  • @react-testing-library/react-hooks version: 7.0.2
  • react version: 15.4.2
  • react-dom version (if applicable): 15.4.2
  • node version:
  • npm (or yarn) version:

Relevant code or config:

function useFoo(foo: string): string;
function useFoo(foo: number): number;
function useFoo(foo: string | number): string | number {
 return foo;
}
test('should allow hook overloading on re-renders', () => {
 renderHook(useFoo, { initialProps: 'string' })
});

What you did:

I have a react hook, that relies on overloading to solve different use-cases. Essentially, this hook has an overload that determines the appropriate way to resolve a value based on its parameter typeof.

What happened:

When faced with an overloadable hook, @react-testing-library/react-hooks isn't appropriately typing either the initialProps for the renderHook method, or the rerender method itself.

Reproduction:

Reproduction

Problem description:

Hook overloading only works when you explicitly call the hook and return it's value on the renderHook method, while when using the renderHook with the initialValue option, it doesn't properly generate the types to match the overload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /