Replies: 2 comments
-
@marksmall Thank you! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I added unit tests to the library. If you're interested in how to mock |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For those that are having a similar problem to me, I've been trying to write a Jest unit test for my
theme-switcher
component, that uses theuseTheme
hook. I initially was getting the error:TypeError: window.matchMedia is not a function
If you google on this you can see there is some documentation . I added this to my test and got further, but again, got another error, this time
TypeError: Cannot read properties of undefined (reading 'addEventListener')
. I therefore amended the solution from the docs to be:Using this in the test file, or in some
setupTests.ts|js
file, should allow you to work with theThemeProvider
in your tests. e.g.Hope this helps anyone suffering the same trouble as I was.
Beta Was this translation helpful? Give feedback.
All reactions