usehooks
usehooks copied to clipboard
Error when running react-script test with jest
Hello,
I tried to use the useMediaQuery hook from your library (btw good job with creating so many useful hooks) import { useMediaQuery } from "@uidotdev/usehooks";
Over the components we have tests that use jest test library. When I run the react-scripts test I get an error regarding the import of the useMediaQuery "SyntaxError: Cannot use import statement outside a module"
"Jest encountered an unexpected token Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax. Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration."
The line it seems to complains is "import * as React from "react";" . Is this something wrong on jest side or something can be done on how we use the "@uidotdev/usehooks" hooks?
any solutions for this
See some more discussion of this in #221
Any progress on this? Can I help by providing a MWE?
https://github.com/uidotdev/usehooks/issues/221#issuecomment-1988680491 (Not sure which issue to comment as #221 seems a little more elaborated.)