Tsu*_*ury 9 testing reactjs jestjs react-native
假设我有这个组件:
import React, { Component } from 'react';
import { Text, TouchableWithoutFeedback, View } from 'react-native';
class MyComp extends Component {
onRowPress() {
this.myCoolFunction();
}
myCoolFunction() {
console.log('hi');
}
render() {
return (
<TouchableWithoutFeedback onPress={this.onRowPress.bind(this)}>
<View>
<Text>Hello World</Text>
</View>
</TouchableWithoutFeedback>
);
}
}
export default MyComp;
Run Code Online (Sandbox Code Playgroud)
如何模拟1点击'TouchableWithoutFeedback'并确保'myCoolFunction'被正确调用1次?
如果它不是必须的,那么我宁愿不添加除'react-dom'和'react-addons-test-utils'之外的更多依赖项.
我看到很多指南声称这个和那个,但我担心它们已经过时了,我想确定我不会经历一些不必要的变通办法并使我的代码膨胀.
我在他们的最新版本中有jest/react/react原生.
编辑:在Jest的官方文档中,它说DOM测试可以使用Enzyme或TestUtils完成.如何使用TestUtils完成此操作?
| 归档时间: |
|
| 查看次数: |
1297 次 |
| 最近记录: |