将RN 16.9.0与Jest一起使用。我试图从组件中窥探一个按钮,但总是收到错误消息。
const spy = jest.spyOn(wrapper.instance(), "handleClick");
handeClick带红色下划线并显示以下错误(也在运行笑话测试时):
类型'“ handleClick”'的参数不能分配给的参数 输入'“ context” | “ setState” | “ forceUpdate” | “渲染” | “ componentDidMount” | “ shouldComponentUpdate” | “ componentWillUnmount” | “ componentDidCatch” | “ getSnapshotBeforeUpdate” | ... 6更多... | “ UNSAFE_componentWillUpdate”'
我的组件如下:
export default class RecordTimer extends React.Component {
handleClick = () => {...}
...
render() {
return (
<Button
onPress={this.handleClick}
...
/>
)
}