Bug running Jest with ScrollView dependant components
See original GitHub issueDescription
When running npm run test
, the default tests index.ios.js
and index.android.js
fail due to the following error:
TypeError: _this._scrollView.scrollTo is not a function
at TabViewPagerScroll._this._scrollTo (node_modules/react-native-tab-view/src/TabViewPagerScroll.js:68:19)
at TabViewPagerScroll.componentDidMount (node_modules/react-native-tab-view/src/TabViewPagerScroll.js:123:197)
at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:265:25
at measureLifeCyclePerf (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:75:12)
at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:264:11
at CallbackQueue.notifyAll (node_modules/react-test-renderer/lib/CallbackQueue.js:76:22)
at ReactTestReconcileTransaction.close (node_modules/react-test-renderer/lib/ReactTestReconcileTransaction.js:36:26)
at ReactTestReconcileTransaction.closeAll (node_modules/react-test-renderer/lib/Transaction.js:206:25)
at ReactTestReconcileTransaction.perform (node_modules/react-test-renderer/lib/Transaction.js:153:16)
at batchedMountComponentIntoNode (node_modules/react-test-renderer/lib/ReactTestMount.js:69:27)
Reproduction
$ react-native init Test
$ cd Test/
$ yarn add react-navigation
$ npm run test
Solution
I’m open to send a PR with a fix if somebody can guide me through this. Could be here https://github.com/facebook/react-native/blob/dbe555ba78d7b0f79e482c62787db2fc3d897848/Libraries/Components/ScrollView/__mocks__/ScrollViewMock.js?
Additional Information
- React Native version: 0.42.0
- Platform: both
- Operating System: macOS Sierra
- Dev tools: iOS 10.2
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Why is ScrollView hiding its children when I examine it using ...
Whenever I try to mount something with a ScrollView component, I can't seem to see below it in the component tree. Here is...
Read more >jest-worker | Yarn - Package Manager
jest -worker ... Module for executing heavy tasks under forked processes in parallel, by providing a Promise based interface, minimum overhead, and bound...
Read more >react-native-swiper - npm
Start using react-native-swiper in your project by running `npm i react-native-swiper`. ... The best Swiper component for React Native.
Read more >Common bugs in React Native ScrollView and how to fix them
React Native's ScrollView component is ubiquitous, but its implementation can sometimes lead to mistakes. Learn what to look out for here.
Read more >20+ Perfect React Native Scroll Component Examples - Morioh
A ScrollView-like component that: Has a parallax background; Has a parallax foreground; Has a fixed or sticky header; Can be nested within other...
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 ran into this issue and was able to mock this simply:
Also, I’m mocking the
Linking
module as well from here that @alvaromb provided:Note, I’ve configured this to be run as part of Jests
setupFiles
configuration.@minhhai2209 Great solution! One small improvement, your code broke all my existing snapshot tests, because the ScrollView mock shipped with react-native renders slightly differently. This worked for me: