Jest - TypeError: Cannot read property 'Commands' of undefined
See original GitHub issueDo you want to request a feature or report a bug?
bug - related to jest
What is the current behavior?
The error TypeError: Cannot read property 'Commands' of undefined
is thrown when i trigger a function that references a <ListView/>
and calls the scrollTo method of the <ListView/>
like below:
// This is a react-native app
// MyComponentTest.js
it('test scrollTo', () => {
const tree = renderer.create(<MyComponent/>).toJSON()
tree.children[0].props.onPress()
})
// MyComponent.js
class MyComponent extends Component {
_scrollToTop = () => {
this.refs.listView.scrollTo({x:0,y:0})
}
render() {
return (
<View>
<TouchableHighlight onPress={this._scrollToTop}/>
<ListView
ref="listView"
{...moreProps}
/>
</View>
)
}
}
When i run the tests, the stack trace ends at ‘Component.scrollResponderScrollTo (node_modules/react-native/Libraries/Components/ScrollResponder.js:380:24)’
The error is caused by the line ‘this.refs.listView.scrollTo({x:0,y:0})’…
Package Versions
I run the react-native app with the following package configuration: “react”: “15.4.1” “react-native”: “0.39.2” “babel-jest”: “17.0.2” “jest”: “17.0.3” “react-test-renderer”: “15.4.1” “babel-preset-react-native”: “1.9.0”
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:7 (2 by maintainers)
A Workaround to fix the Problem with srcollTo:
+1 same issue