-
Notifications
You must be signed in to change notification settings - Fork 688
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
[bug] Package throws import errors when running jest test suites #461
Comments
Thanks for the detailed issue and minimal reproducible example @brightiron – we'll check it out! |
Quick update from my end.
However jest now complains at this import The only two workarounds i've found are:
The problem with the latter for us is that it increases the runtime of our test suite considerably. In the longterm, it seems like each of these components in rainbowkit could potentially import their own styles vs relying on a style import from the project the library is installed in. Would also remove an install/configuration step for anyone using the package. It'd also be awesome if we didn't have to use Appreciate you guys. |
Any updates on this? I'm having the same problems and was only able to workaround using @brightiron suggestion, but as mentioned it greatly increased runtime. |
Having the same issues when using create-react-app + chakra. |
If you are using NextJS there is a known issue where next ignores your transformIgnorePatterns: vercel/next.js#35634 |
An alternative temporay fix is to mock the rainbowkit like this: jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: {
Custom: jest.fn(),
},
})); Add this line to your |
Reproducing the same with latest nextjs + tailwind + wagmi |
I was having issues with mocking only the Connect Button due to how we instantiate our providers and default supported chains, in case anyone is stumbling on the same issue you can mock the getDefaultWallets function in the same way by adding |
For those of you on NextJS, fixed it locally by mocking the ConnectButton and getDefaultWallets func per @sudoFerraz and @pyk I can now run jest test locally without problem, however when running in github actions, tests seem to run indefinitely. Running with the transformIgnorePatterns from @brightiron, I get this locally:
is there any other way to ignore rainbowkit with Jest tests? edit: added
in jest.setup |
Tried solutions above but I'm getting |
We just published a fix for the CSS import issue mentioned above in RainbowKit v0.5.2. We were using the @brightiron I'd be keen to hear how much of an improvement this is to your setup. |
Closing this as fixed. Feel free to continue the discussions! If anything else arises, we can reopen this issue. |
@markdalgleish - ty for the fix. lemme do some benchmarking this week and reply here with some results. We're also in process of migrating to vite / vitest for local dev, and I have some mocks created that play nicely with rainbowkit & custom button implementations. Appreciate you guys! |
In case you want to customize the mocked value for the jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: () => <div>ConnectButton</div>,
...
})); |
Is there an existing issue for this?
RainbowKit Version
0.2.2
wagmi Version
0.4.6
Current Behavior
Package causes jest to throw a 'Cannot use import statement outside a module' error
Hello Sers!
Digging this project and appreciate all you guys are doing.
Running into an issue when running our test suite where this package throws import errors. There are some things we can do on our side to workaround (i.e. mock import, transformIgnorePatterns, etc) but this is not something we've had to do for any other dependency.
To rule out our project specifically i've created a fresh create-react-app, installed rainbowkit, wagmi, and ethers. When running
yarn test
we experience the exact same behavior.I imagine this is something others will soon encounter.
Expected Behavior
Package should not throw import errors when running jest test suite and shouldn't have to mock package import.
Steps To Reproduce
Checkout: https://github.com/brightiron/rainbowkit-jest-test (Clean create-react-app project with only wagmi, rainbowkit and ethers installed)
Run:
yarn install
yarn test
Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)
https://github.com/brightiron/rainbowkit-jest-test
Anything else?
No response
The text was updated successfully, but these errors were encountered: