react-native-scrollable-tab-view icon indicating copy to clipboard operation
react-native-scrollable-tab-view copied to clipboard

Warning when test on Jest

Open rodolfobarretoweb opened this issue 7 years ago • 15 comments

React version: 16.0.0-alpha.6 React native version: 0.43.3

Animated: useNativeDriver is not supported because the native animated module is missing. Falling back to JS-based animation. To resolve this, add RCTAnimation module to this app, or remove useNativeDriver. More info: https://github.com/facebook/react-native/issues/11094#issuecomment-263240420

rodolfobarretoweb avatar May 24 '17 01:05 rodolfobarretoweb

Still happening with v0.6.7 and RN 0.48

rknell avatar Sep 05 '17 11:09 rknell

My tests are failing with Invariant Violation: Native animated module is not available if I remove <ScrollableTabView> they passes.

matart15 avatar Sep 29 '17 06:09 matart15

I have the same issue and it happens when I try to render the component using react-test-renderer while running the test in jest

mateen-hussain avatar Nov 14 '17 21:11 mateen-hussain

Hello.

NativeAnimatedHelper is not mocked by default; I got rid of this warning by adding a

jest.mock('NativeAnimatedHelper');

in my jest setup file.

christianchown avatar Nov 20 '17 11:11 christianchown

thanks @christianchown , that got me past that step, now I am stuck with

TypeError: Cannot read property 'addListener' of undefined
    at AnimatedValue._startListeningToNativeValueUpdates (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedValue.js:194:75)
    at AnimatedValue.__makeNative (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedValue.js:102:6)
    at AnimatedDivision.__makeNative (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedDivision.js:33:9)
    at AnimatedValue.__makeNative (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedWithChildren.js:30:7)
    at AnimatedValue.__makeNative (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedValue.js:99:109)
    at AnimatedDivision.__makeNative (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedDivision.js:33:9)
    at AnimatedValue.__addChild (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedWithChildren.js:46:7)
    at AnimatedDivision.__attach (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedDivision.js:53:9)
    at AnimatedDivision.__addChild (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedWithChildren.js:41:6)
    at AnimatedInterpolation.__attach (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedInterpolation.js:344:14)
    at AnimatedInterpolation.__addChild (/Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedWithChildren.js:41:6)
    at /Users/<redacted>/app/node_modules/react-native/Libraries/Animated/src/nodes/AnimatedTransform.js:75:7

RN 0.50.3 "react-native-scrollable-tab-view": "^0.8.0",

rknell avatar Dec 19 '17 00:12 rknell

I'm experiencing @rknell's issue, given @christianchown's solution. Has there been any headway on this issue?

DoWhileGeek avatar Mar 29 '18 23:03 DoWhileGeek

+1

experiencing @rknell's problem as well

igez avatar May 21 '18 15:05 igez

+1 Also experiencing @rknell's problem

dammy95 avatar May 24 '18 11:05 dammy95

So I found a way around this by doing this:

  1. Create react-native-scrollable-tab-view.js in your app/__mocks__ folder.
  2. In the react-native-scrollable-tab-view.js file, insert this:
export const NativeAnimatedHelper = {
  addListener: jest.fn(),
};
  1. add in jest.mock('react-native-scrollable-tab-view', () => 'NativeAnimatedHelper'); in your jest test file.

Hope this helps!

dammy95 avatar May 24 '18 14:05 dammy95

jest.mock('NativeAnimatedHelper')

This didn't work for me. After googling I found this: https://stackoverflow.com/questions/58257932/cannot-find-module-nativeanimatedhelper-when-using-jest-mock

which you just need to do this instead: jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper')

betoharres avatar Mar 01 '20 23:03 betoharres

2021 update - a working fix for me now is

jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');

christianchown avatar Sep 27 '21 11:09 christianchown

Can anyone please tell me where is the jest.mock available to change

WarunaWMPL avatar Oct 06 '21 14:10 WarunaWMPL

@WarunaWMPL

Can anyone please tell me where is the jest.mock available to change

you don't need to import it, you just add this to .eslintrc.js

module.exports = {
  root: true,
  env: {jest: true},
  // ....
}

and create a js file with the library name inside the __mock__ directory and paste that mock inside the file. the jest variable will be set once it reaches the mock file, dont worry

betoharres avatar Oct 06 '21 15:10 betoharres

@betoharres it worked. Thanks

WarunaWMPL avatar Oct 07 '21 02:10 WarunaWMPL

So I found a way around this by doing this:

  1. Create react-native-scrollable-tab-view.js in your app/__mocks__ folder.
  2. In the react-native-scrollable-tab-view.js file, insert this:
export const NativeAnimatedHelper = {
  addListener: jest.fn(),
};
  1. add in jest.mock('react-native-scrollable-tab-view', () => 'NativeAnimatedHelper'); in your jest test file.

Hope this helps!

it worked, thanks.

mohmmd-ishtiaq avatar Nov 15 '21 14:11 mohmmd-ishtiaq