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

Jest encountered an unexpected token #3626

Open
ND56 opened this issue Apr 3, 2024 · 2 comments
Open

Jest encountered an unexpected token #3626

ND56 opened this issue Apr 3, 2024 · 2 comments

Comments

@ND56
Copy link

ND56 commented Apr 3, 2024

The Issue

  • Tests fail when executed due to unexpected react-dnd syntax:
  • image

Relevant Package Versions / Background

  • App bootstrapped with "create react app"
  • "react": "18.2.0"
  • "react-dnd": "^16.0.1",
  • "react-dnd-html5-backend": "^16.0.1",

This Issue Was Previously Reported

  • Looks like this issue was previously reported and was ostensibly resolved: Cannot test an app which imports useDrag #1458
  • The guidance there was to use jest's moduleNameMapper to resolve the issue
  • However, based on the comment thread in that issue, it looks like that was allegedly no longer necessary?
  • Either way, trying it now did not resolve my issue:
  • image
  • image

Question

Any other advice on how we can resolve this?

Thanks!

@ND56
Copy link
Author

ND56 commented Apr 3, 2024

I can resolve the error by adding this jest override, but I'm just wondering if there's any other recommended approach:

  "jest": {
    "transformIgnorePatterns": [
      "/node_modules/react-dnd/dist/index/"
    ]
  }

@abglassford
Copy link

abglassford commented Apr 5, 2024

I can resolve the error by adding this jest override, but I'm just wondering if there's any other recommended approach:

  "jest": {
    "transformIgnorePatterns": [
      "/node_modules/react-dnd/dist/index/"
    ]
  }

I have the same issue as OP. Tried what he mentioned above with transformIgnorePatterns with no success.

Just kidding. I had my jest.config.js set up like this:

module.exports = {
  ...a bunch of stuff,
  transformIgnorePatterns: [
    'node_modules/(?!@<some package here>)',
    'node_modules/(?!react-dnd|core-dnd|@react-dnd|dnd-core|react-dnd-html5-backend)',
  ],
}

... which didn't work. But when I set it like this:

module.exports = {
  ...a bunch of stuff,
  transformIgnorePatterns: [
    'node_modules/(?!@<some package here>|react-dnd|core-dnd|@react-dnd|dnd-core|react-dnd-html5-backend)',
  ],
}

It did!

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

2 participants