[英]React Native Enzyme testing useEffect hook testing
I have a useEffect
hook inside my component.我的组件中有一个
useEffect
钩子。 I'm testing with Enzyme.我正在用酶测试。 Not sure how I can test the functions calls inside the hook:
不知道如何测试钩子内的函数调用:
useEffect(() => {
onChangeText(initialLocation.displayName);
setAutocomplete(null);
}, [initialLocation]);
Your useEffect hook is listening to changes from the initialLocation
prop.您的 useEffect 钩子正在监听来自
initialLocation
道具的变化。 So to test this, you should test the entire component using something like jest, or react testing library.因此,要对此进行测试,您应该使用诸如 jest 或 react 测试库之类的东西来测试整个组件。 Change the value of
initialLocation
and make assertions as to how the component should react to those prop changes.更改
initialLocation
的值并断言组件应如何对这些 prop 更改做出反应。 I obviously can't see your entire component in this example, but you could make the assertion that the correct displayName
can be found in the dom tree when changing the prop在这个例子中我显然看不到你的整个组件,但是你可以断言在改变 prop 时可以在 dom 树中找到正确的
displayName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.