testing-library / testing-library/react-testing-library
testing custom hook within a component scope throws TypeError not a function
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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