-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Module not found in jest tests #29
Comments
I had the same issue, resolved via:
import {
RefObject,
useEffect,
} from "react"
import autoAnimate from "@formkit/auto-animate"
// https://github.com/formkit/auto-animate/issues/11
export const useAutoAnimate = (ref: RefObject<HTMLElement | null>) => {
useEffect(() => {
ref.current && autoAnimate(ref.current)
}, [ref])
}
"jest": {
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\](?!(@formkit/auto-animate)).+\\.(js|jsx|mjs|cjs|ts|tsx)$"
]
}, Step 2 should fix the new error from step 1:
|
Thanks for the hint @StK88 ! I tried what you suggested, with and without the "custom" useAutoAnimate hook but I got this error (in test environment only):
|
@Clm-Roig, forgot about that, it also requires mock of // src/setupTests.ts
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
})) |
Oh yes I saw this solution when doing my research, but I hoped there will be something else more elegant... Anyway, thank you very much for your time, it works like a charm! |
Hi all, I tried all, the current solution is not working for me on TS, also not but using allowJs true, any idea? |
I fixed this via https://jestjs.io/docs/manual-mocks#mocking-node-modules
|
If you're not using the hook this fixed it for me after looking at Lines 644 to 654 in 3dea1af
Insert the following under the file const autoAnimate = jest.fn((el: Element) => ({
parent: el,
enable: jest.fn(),
disable: jest.fn(),
isEnabled: jest.fn(),
}));
export default autoAnimate; |
I'm getting the same issue with Vue and Vitest. Adding this to the test file creates different issues:
|
Justin, can you give your opinion about this matter? I questing this because I think Auto Animate it's an incredible library, and the "main marketing" slogan it's that a library that has "zero-config". And not for me, but for a lot of devs, Jest is one of the most used js testing libraries, and because of that, I think that's an important issue to discuss. If the library can't do anything about it, I think that's a good idea to have a disclaimer on the official page about how to integrate the library and what's configs need to use with Jest. And if have anything to do to turn Auto Animate into a "zero config" with Jest, anyone is working on it or anyone can help? |
@ArthurPedroti Does this not work for you? #29 (comment) |
Yes, this is working, my question is more embracing, thinking about newcomers and how is the experience of you facing an error right away and don't have any docs about this error or "official" docs about how to integrate these two libraries. |
Honestly im not sure what we can do about this. Perhaps a note in the docs would be appropriate. Happy to accept a PR for that! In the meantime im closing this issue since it is related to module definitions which are unrelated and I believe have improved. 👍 |
Hi,
I'm using auto-animate on a typescript React app and I'm testing it with Jest. When I'm running the app, everything is fine. But when I'm running the tests, I get this error:
Complete error:
I don't understand why Jest can't find the module... I'm using node v16.15.0, npm v8.5.5 and react-scripts v5.
Here is my package.json :
Click to see
My TS config :
Click to see
I understand that maybe this is not related to this library in particular: feel free to tell me to ask this question elsewhere.
Thank you for this module, it's awesome!
The text was updated successfully, but these errors were encountered: