usehooks icon indicating copy to clipboard operation
usehooks copied to clipboard

Error when running react-script test with jest

Open hadrian625 opened this issue 1 year ago • 3 comments

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?

hadrian625 avatar Nov 14 '23 15:11 hadrian625

any solutions for this

Arunjenson avatar Nov 17 '23 11:11 Arunjenson

See some more discussion of this in #221

nicogreenarry avatar Nov 17 '23 20:11 nicogreenarry

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.)

Tilogorn avatar Mar 11 '24 15:03 Tilogorn