0

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?

  • Can you share how you import the component in the test as well as the import lines in both the component and the hook? I know this seems facile and quite specific, but I have an idea about what it is as seen it before. – adsy Oct 16 '22 at 18:32
  • @adsy in the test ` import { Comp } from './comp'; import { Proivder } from '@context/provider'; ` in the provider: ``` import { useEmployees } from '@customers/.../resources'; ``` does this help? – Ahmed Sarhan Oct 17 '22 at 08:40
  • Test one is fine, but im not sure where the provider is from. The additional ones needed are those in the file in which `useCustomHook` is located as well as, crucially, the component you are testing `useCustomHook` with -- as you mention you are testing them together. – adsy Oct 17 '22 at 15:24

0 Answers0