react-native-animatable: Unable to run tests
I’m unable to test components having Animatable.View, I’m seeing the following error:
TypeError: UIManager.updateView is not a function
at Component.setNativeProps (node_modules/react-native/Libraries/Renderer/src/renderers/native/NativeMethodsMixin.js:157:11)
at AnimatedProps.callback [as _callback] (node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:1757:20)
at AnimatedProps.update (node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:1625:6)
at node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:228:69
at Set.forEach (native)
at _flush (node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:228:16)
at AnimatedValue._updateValue (node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:907:1)
at AnimatedValue.setValue (node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:738:6)
at AnimatableComponent.startAnimation (node_modules/react-native-animatable/createAnimatableComponent.js:312:16)
at startAnimation (node_modules/react-native-animatable/createAnimatableComponent.js:242:8)
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 8
- Comments: 21 (2 by maintainers)
I had the same issue, with an error saying
TypeError: _this.backdropRef.transitionTo is not a functionAfter browsing all the mocks in this issue, I found that a modified version of @scerelli suggestion should work:
(original: https://github.com/oblador/react-native-animatable/issues/97#issuecomment-307377808)
I solved this way, under
__mocks__if using jest, create areact-native-animatable.jsfile with this:This is the closest issue we found when trying to write a test for a component that uses
react-native-animatable’s wrappedViewcomponent.We were getting a
TypeError: Cannot read property 'validAttributes' of undefined.We got around this by mocking animatable and using RN’s
Viewin our tests instead.Under
__mocks__if using jest, create areact-native-animatable.jsfile with this:This mock works for me
I have encountered a similar issue. As pointed out in Jest docs for react-native. Most of the NPM packages depend on babel transformations and don’t have their source code “pre-compiled” therefore errors are encountered. That’s where transformIgnorePatterns setting for Jest comes to play.
Adjusting settings to:
Solved any babel transformations related errors. However, a manual function mock is still required due to an error:
TypeError: Animatable.createAnimatableComponent is not a functionCreating a __mocks__ folder on the project’s root directory (where node_modules folder resides) and a file react-native-animatable.js with the content of:
Solved all the issues for me. However, one might need to expand the manual mock based on the functionality used. Personally, I have used only createAnimatableComponent hence minimal manual mock was enough.
This partly works for me. It solves the TypeError on
initializeRegistryWithDefinitionsbut thereforetransitionTois not working anymore because it uses the View component of ‘react-native’.Can confirm, receiving same error as markhaasjes with:
Don’t know about your test setup, but you probably just need to mock it.