useAnimatedStyle broken in Jest
See original GitHub issueDescription
I’ve upgraded to 2.0.0 and trying #1731 mocks on my project. I’m getting this error:
TypeError: Cannot convert undefined or null to object
at Function.values (<anonymous>)
31 | }, [isVisible])
32 |
> 33 | return useAnimatedStyle(() => ({
| ^
34 | transform: [{ translateY: offsetY.value }],
35 | opacity: interpolate(offsetY.value, [from, to], [0, 1], Extrapolate.CLAMP),
36 | }))
at useAnimatedStyle (node_modules/react-native-reanimated/src/reanimated2/Hooks.js:421:25)
at useAnimateVisibility (src/app/hooks/useAnimateVisibility.tsx:33:10)
at FormErrorMessage (src/app/components/Forms/FormErrorMessage.tsx:16:27)
at renderWithHooks (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5552:18)
at mountIndeterminateComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7918:13)
at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9019:16)
at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12649:12)
at workLoopSync (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12622:22)
at performSyncWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12333:9)
at node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1825:24
at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:653:12)
at runWithPriority (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1775:10)
at flushSyncCallbackQueueImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1820:7)
at flushSyncCallbackQueue (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1808:3)
at batchedUpdates (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12401:7)
at act (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14936:14)
at renderWithAct (node_modules/@testing-library/react-native/build/render.js:68:20)
at render (node_modules/@testing-library/react-native/build/render.js:46:20)
at renderWithProviders (src/app/utils/testing/render.tsx:47:10)
at _callee2$ (src/features/forgotPassword/components/ForgotPasswordForm.test.tsx:24:27)
at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:293:22)
at Generator.next (node_modules/regenerator-runtime/runtime.js:118:21)
at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
at invoke (node_modules/regenerator-runtime/runtime.js:154:20)
at node_modules/regenerator-runtime/runtime.js:189:11
at callInvokeWithMethodAndArg (node_modules/regenerator-runtime/runtime.js:188:16)
at AsyncIterator.enqueue (node_modules/regenerator-runtime/runtime.js:211:13)
at AsyncIterator.next (node_modules/regenerator-runtime/runtime.js:118:21)
at Object.<anonymous>.exports.async (node_modules/regenerator-runtime/runtime.js:238:14)
at Object._callee2 (src/features/forgotPassword/components/ForgotPasswordForm.test.tsx:21:26)
Looks like something on useAninimatedStyle is broken. I don’t have sure, but it looks like the only offending error on my test. suit
Package versions
- React Native: 0.63
- React Native Reanimated: 2.0.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Testing error: useSharedValue is not a function while testing
Description. I'm using react-native-reanimated and when I'm testing, useSharedValue throws an error that it's not a function when using jest ...
Read more >Testing with Jest | React Native Reanimated - Software Mansion
Reanimated test mocks use web implementation of Reanimated2. Before you begin using Reanimated mocks you need some setup actions.
Read more >Reanimated 2 - the new approach to creating animations in ...
The next and one of the most important hook is useAnimatedStyle one. Inside this hook, we define style properties we want to be...
Read more >react-native-reanimated: Versions - Openbase
Fix Jest 28+ expect.extend is not a function error by @yusufyildirim in ... Fix problem with null values in hooks useDerivedValue , useAnimatedStyle...
Read more >What's wrong with snapshot tests. Since snapshot ... - Medium
When Jest announced snapshot tests in 2016, I was very excited, but since then I've ... That's a problem: you don't know if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m facing the same issue with
useDerivedValue
in Jest environment, this line https://github.com/software-mansion/react-native-reanimated/blob/master/src/reanimated2/Hooks.js#L543 throws:@piaskowyk Just found what was wrong.
I was using a custom
babel.config.js
which specifies different plugins per environment, like this:I found that
react-native-reanimated/plugin
is needed when testing too. I’ve just added it tobaseConfig
and it fixed the bug.