当我运行jest时,我遇到了包findNodeHandle
react-native
的问题。
我的代码是这样的:
import { findNodeHandle, TextInput } from 'react-native';
export default class Input extends Component {
componentDidMount() {
findNodeHandle(this.refInput);
}
render() {
return (
<TextInput
ref={ref => this.refInput = ref}
/>
)
}
当我运行开玩笑时,它会显示此错误:
Invariant Violation: Unable to find node on an unmounted component.
at invariant (node_modules/react-native/node_modules/fbjs/lib/invariant.js:44:15)
at findCurrentFiberUsingSlowPath (node_modules/react-native/Libraries/Renderer/ReactNativeFiber-dev.js:562:8)
at findCurrentHostFiber$1 (node_modules/react-native/Libraries/Renderer/ReactNativeFiber-dev.js:609:19)
at Object.findHostInstance (node_modules/react-native/Libraries/Renderer/ReactNativeFiber-dev.js:3078:15)
at Object.<anonymous>.injectedFindNode (node_modules/react-native/Libraries/Renderer/ReactNativeFiber-dev.js:3236:33)
at findNodeHandle (node_modules/react-native/Libraries/Renderer/ReactNativeFiber-dev.js:3246:25)
at findNumericNodeHandleFiber (node_modules/react-native/Libraries/Renderer/ReactNativeFiber-dev.js:3250:14)
我想是在嘲笑包react-native
并对待函数findNodeHandle
,但我找不到一种方法来进行模拟。
我怎么解决这个问题?
react-native:49.5
开玩笑:21.2.1
感谢