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

Error when running react-script test with jest #264

Open
hadrian625 opened this issue Nov 14, 2023 · 3 comments
Open

Error when running react-script test with jest #264

hadrian625 opened this issue Nov 14, 2023 · 3 comments

Comments

@hadrian625
Copy link

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?

@Arunjenson
Copy link

any solutions for this

@nicogreenarry
Copy link

See some more discussion of this in #221

@Tilogorn
Copy link

Any progress on this? Can I help by providing a MWE?

#221 (comment)
(Not sure which issue to comment as #221 seems a little more elaborated.)

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