Closed strmer15 closed 2 years ago
Try this:
https://dev.to/bytebodger/how-i-fixed-the-unexpected-token-error-in-jest-4o1j
https://stackoverflow.com/questions/51994111/jest-encountered-an-unexpected-token
For anyone using create-react-app, only certain jest configurations can be changed in package.json when using create-react-app.
I have issues with Jest picking up an internal library, Jest would display 'unexpected token' errors wherever I had my imports from this library.
To solve this, you can change your test script to the below: "test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(<your-package-goes-here>)/)'",
Ah, ok - so maybe the newest version used some syntax that Jest is unable to transform correctly? I guess I can either try to explicitly ignore it or else I'll have to see if there's some kind of babel plugin I need to add. Thanks, for the help!
Let me know if you can make it work. I'd also suggest you clone the full repo and run the example in sample-runs
as described at the top of the Readme (person schema). It references the distribution js file in dist/
directly.
Not exactly sure why the lib suddenly breaks babel. Perhaps if I delete dist
locally and publish the lib again it will generate a clean dist and deployment with no such issue.
FYI, I just upgraded to 1.11.5 and this seems to work correctly now, so not sure what happened 🤷
Actually, I thought that had fixed it, but it didn't - I ended up just using 'node_modules/(?!(schema-to-yup)/).+\\.(js|jsx|ts|tsx)$'
in my transformIgnorePatterns
and that did the trick.
I just upgraded to the newest version of
schema-to-yup
, 1.11.4, from 1.11.2, and encountered the following error whenever I run my React component unit tests:I'm running React 17.0.2, Jest 27.4.7, Node 12.22.8, and Typescript 4.4.4 - this is a CRA-app that I've ejected. When the test fails it also prints this out at the top: