I bumped RC 1 -> RC 2 in my project and suffered JEST error like the following
โ Test suite failed to run
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'NativeReanimated' could not be found. Verify that a module by this name is registered in the native binary.
at invariant (node_modules/invariant/invariant.js:40:15)
at Object.getEnforcing (node_modules/react-native/Libraries/TurboModule/TurboModuleRegistry.js:39:3)
at Object.<anonymous> (node_modules/react-native-reanimated/src/reanimated2/NativeReanimated.native.js:5:23)
at Object.<anonymous> (node_modules/react-native-reanimated/src/reanimated2/WorkletEventHandler.js:1:1)
My mock file is like that.
// @ts-ignore https://github.com/wcandillon/react-native-redash/issues/395
global.__reanimatedWorkletInit = () => {};
jest
.mock('react-native-reanimated', () => ({
...require('react-native-reanimated/mock'),
}))
.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
Test should success
16.13.10.63.42.0.0-rc0214.7.0Hello!
It seems like there are some problems with your issue. Please fix them and wait for the validator to confirm that everything is alright.
Thank you!
Validator encountered the following problems:
I can also confirm that changing my project from 2.0.0-rc2 to 2.0.0-rc1 stopped jest from failing. Would really like RC2 to work as the withTiming caused crashes on ios in this version..
I'm also getting the following now when trying to render the app:
renders correctly
TypeError: (0 , _reactNativeReanimated.useSharedValue) is not a function
36 |
37 | const Notch: React.FC<Props> = ({ pressed }) => {
> 38 | const offset = useSharedValue(0);
| ^
39 |
40 | const animatedStyles = useAnimatedStyle(() => {
41 | return {
at Notch (src/components/NumPad/Notch.tsx:38:18)
at renderWithHooks (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6156:18)
at mountIndeterminateComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8690:13)
at beginWork$1 (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10052:16)
at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14694:12)
at workLoopSync (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14667:22)
at performSyncWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14366:11)
at node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2063:24
at unstable_runWithPriority (node_modules/react-test-renderer/node_modules/scheduler/cjs/scheduler.development.js:818:12)
at runWithPriority (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2013:10)
I believe I'm missing some mocks now that were moved into master last November, which I guess are in the RC2?
@LiamDotPro V2 mocks are included in RC02. I suggest you to inspect mock.js file in repo and use it correctly.
Well I can't currently run jest at RC2 because of Invariant Violation: so I downgraded to RC1 which now presents me with this type error. I'm using the following inside react-native-reanimated.js export * from 'react-native-reanimated/mock';
This is not only Jest related. Same happens when
Remote debugging issue indicates me Hermes comes into play. That is not viable on iOS for me ๐คทโโ๏ธ
@karol-bisztyga Can we expect an update on the validity / if it is planned to fix?
I opened a PR, but if you guys want a temporary fix. Use ds300/patch-package and put this on patches/react-native-reanimated+2.0.0-rc.2.patch:
diff --git a/node_modules/react-native-reanimated/mock.js b/node_modules/react-native-reanimated/mock.js
index 3bc10c5..c26bce3 100644
--- a/node_modules/react-native-reanimated/mock.js
+++ b/node_modules/react-native-reanimated/mock.js
@@ -234,6 +234,7 @@ module.exports = {
__esModule: true,
...Reanimated,
+ ...ReanimatedV2,
default: {
...Reanimated,
diff --git a/node_modules/react-native-reanimated/src/reanimated2/mock.js b/node_modules/react-native-reanimated/src/reanimated2/mock.js
index e4b6a8c..7b4ebe7 100644
--- a/node_modules/react-native-reanimated/src/reanimated2/mock.js
+++ b/node_modules/react-native-reanimated/src/reanimated2/mock.js
@@ -1,11 +1,18 @@
-const hooks = require('./Hooks');
/* eslint-disable standard/no-callback-literal */
+const useRef = require('react').useRef
const NOOP = () => {};
const ID = (t) => t;
const ReanimatedV2 = {
- useSharedValue: hooks.useSharedValue,
+ useSharedValue: (init) => {
+ const ref = useRef(null);
+ if (ref.current === null) {
+ ref.current = { value: init };
+ }
+
+ return ref.current
+ },
useDerivedValue: (a) => ({ value: a() }),
useAnimatedScrollHandler: () => NOOP,
useAnimatedGestureHandler: () => NOOP,
Most helpful comment
This is not only Jest related. Same happens when
Remote debugging issue indicates me Hermes comes into play. That is not viable on iOS for me ๐คทโโ๏ธ