【发布时间】:2015-08-14 22:05:19
【问题描述】:
我正在尝试弄清楚如何测试 React Native(不是 React JS)组件。即使看 React Native 的入门代码,也很难看出如何测试它。
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
我已经能够使用 Babel 转译 JSX 语法以及使用 Mockery 模拟 React 库方法 createClass 和 StyleSheet.create,但最终,我似乎无法创建任何有意义的测试。
【问题讨论】:
-
我认为我们想要一些类似于用于 React web 的 Reacts Shallow Rendering 测试技术。我在这里发布了这个问题:stackoverflow.com/questions/32804218/…