testing-library / testing-library/react-testing-library

testing custom hook within a component scope throws TypeError not a function

Open
#1,144 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
19.7k
Forks
1.2k
Avg merge
3d 16h
Merged PRs (30d)
1

Description

when I run my unit tests to test componernts, I recieve errors similar to this one in multiple places:
TypeError: (0 , _fileName.useCustomHook) is not a function
when I test the hook itself alone it works fine, but I don't want to test the hook I want to test the component and the component have data that depends on my custom hook

Notes:

  • this was working last week with no errors and I didn't edit any code
  • I have looked at the packages nothing was updated since then
  • the codebase is Next.js so we can't update RTL to v13 yet as we have React v17 and the dep. tree won't fit together so we have
    @testing-library/react": "^12.1.2 and @testing-library/react-hooks: "^8.0.1",
  • I have updated RTL to 12.1.5 which is the latest version of v12 but same error
    can someone please help with this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or failing test are named. Start by reproducing the component test with the listed React 17, Next.js, @testing-library/react 12.1.5, and @testing-library/react-hooks 8.0.1 versions, then trace the custom hook import used by the component. Done means identifying a reproducible cause and documenting the compatible fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.