Skip to content
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

Cannot read properties of undefined (reading '__H') #20

Open
pitis opened this issue Jan 11, 2023 · 4 comments
Open

Cannot read properties of undefined (reading '__H') #20

pitis opened this issue Jan 11, 2023 · 4 comments

Comments

@pitis
Copy link

pitis commented Jan 11, 2023

Hey there guys, I am trying to test some of my custom hooks that work in prod, but don't work with @testing-library/preact-hooks.

I am trying to write some unit tests where I check the height of a banner. Initially I used jest, but now I'm using vitest, which has an API almost identical to jest.

All the tests pass besides the ones on the custom hooks. This seems like a package issue.

Thanks!

image

Stack Info:
Preact: 10.11.3
Vite: 4.0.0
Vitest: 0.27.0
@testing-library/preact-hooks: 1.1.0

@ositowang
Copy link

we have a similar issue...have you found a solution @pitis

@pitis
Copy link
Author

pitis commented Feb 8, 2023

@ositowang I believe the issue is that useState is not mocked. So if you create a way to mock useState, it may work for the other hooks

@hckjck
Copy link

hckjck commented Jun 19, 2023

https://preactjs.com/guide/v10/preact-testing-library#testing-preact-hooks using renderHook makes the difference.

@Cipscis
Copy link

Cipscis commented Oct 30, 2023

I spent all of yesterday trying to figure out how to get this working. This issue is quite old now, but on the off chance it might help anyone else with this problem here's what I've found.

@testing-library/preact-hooks seems to be intended to be used with older versions of Preact. Because of conflicting peer dependencies, it can't be used alongside the latest version of @testing-library/preact.

However, if you're using Preact 10, then you can import renderHook from @testling-library/preact instead. For my setup, at least, this resolved my issue and I'm not able to test my hooks as expected.

Unfortunately, at the time I'm writing this, the testing documentation for the latest version of Preact currently recommends importing renderHook from the outdated @testing-library/preact-hooks library.

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

No branches or pull requests

4 participants