Comments (12)
I fixed this via https://jestjs.io/docs/manual-mocks#mocking-node-modules
*Note my jest config includes roots: ["<rootDir>/jest"]
jest/__mocks__/@formkit/auto-animate/react.js
const useAutoAnimate = () => [null];
export { useAutoAnimate };
from auto-animate.
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 __mocks__/@formkit/auto-animate/index.ts
const autoAnimate = jest.fn((el: Element) => ({
parent: el,
enable: jest.fn(),
disable: jest.fn(),
isEnabled: jest.fn(),
}));
export default autoAnimate;
from auto-animate.
@Clm-Roig, forgot about that, it also requires mock of global.ResizeObserver
in src/setupTests.ts:
// src/setupTests.ts
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}))
from auto-animate.
I had the same issue, resolved via:
- switch to
autoAnimate
withuseRef
instead ofuseAutoAnimate
:
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])
}
- set/extend jest settings in
package.json
(source facebook/create-react-app#11946 (comment)):
"jest": {
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\](?!(@formkit/auto-animate)).+\\.(js|jsx|mjs|cjs|ts|tsx)$"
]
},
Step 2 should fix the new error from step 1:
export { autoAnimate as default, getTransitionSizes, vAutoAnimate };
^^^^^^
SyntaxError: Unexpected token 'export'
from auto-animate.
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!
from auto-animate.
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.
from auto-animate.
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):
ReferenceError: ResizeObserver is not defined
from auto-animate.
Hi all, I tried all, the current solution is not working for me on TS, also not but using allowJs true, any idea?
from auto-animate.
I'm getting the same issue with Vue and Vitest.
ReferenceError: ResizeObserver is not defined
Adding this to the test file creates different issues:
window.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))
import { useAutoAnimate } from "@formkit/auto-animate/vue";
describe("testsuite", () => {...
from auto-animate.
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?
from auto-animate.
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)
from auto-animate.
Honestly im not sure what we can do about this. ResizeObserver
is increasingly part of the general web stack, but sadly it is not included in JSDom βΒ jsdom/jsdom#3368. I donβt think we should mock resize observer ourselves.
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. π
from auto-animate.
Related Issues (20)
- Bug when deleting element of the array in React 18
- Inconsistent jumping inside flex item HOT 1
- Not working HOT 4
- Vue Virtual Scroller
- Wrong arguments order in AutoAnimationPlugin declaration
- Animate across lists? Across all elements inside a `ul`?
- How should I use fixed centering layout? HOT 1
- Incorrect rounding of element sizes while animating HOT 2
- When the page is refreshed, the component has no animation.
- Vue useAutoAnimate not working with v-if
- does not provide an export named 'autoAnimate'
- Animation starting coords are buggy when the container has transitioned positions
- How to add auto-animate to custom components (NuxtUI) HOT 1
- Headless UI + Auto-Animate | Issue with auto-animate conflicting HOT 1
- nuxt3 3.10.3 does not provide an export named 'autoAnimate' HOT 1
- I added the element from the front but the animation still appears from the last one HOT 1
- React.Children.map issue HOT 1
- How to animate single element? HOT 3
- The compatibility of TR tags is a bit difficult to use, and the TR animation effect has become distorted
- CDN support ?? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto-animate.