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

Facing issue white writing jest test cases for a module which imports allotment. #666

Open
avanish-srivastava opened this issue Jul 17, 2023 · 2 comments

Comments

@avanish-srivastava
Copy link

Hi

I have a react application in which I have used "allotment" in one of my component and to test the application I have used "Jest" and "react testing library". Now while testing my component which has "allotment", it is giving me this below error.

image

I tried this with a sample application also and there also I'm facing this same issue.
So what can be the possible reason for this issue?

Link for that sample application :- https://github.com/avanish2403/OpenfinContextSharing/tree/AppWithJestTestCases

@AndreSilva1993
Copy link

AndreSilva1993 commented Jul 20, 2023

Have you tried using the transformIgnorePatterns option of Jest? https://jestjs.io/docs/configuration#transformignorepatterns-arraystring

I was also having this issue and pay attention to the extension of the file that Jest is complaining which is .mjs. So if like me, you have something like this

transform: {
  '\\.[jt]sx?$': 'babel-jest',
},

you have to change to:

transform: {
  '\\.m?[jt]sx?$': 'babel-jest',
},

@lukedukeus
Copy link

lukedukeus commented Sep 12, 2023

I just ran into the same issue, but was unable to fix it, so I just mocked the component.

jest.mock('allotment', () => ({
  Allotment: jest.fn().mockImplementation(({ children }) => <div>{children}</div>),
}));

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

3 participants