1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 | import PropTypes from 'prop-types';
|
11 |
|
12 | var createClass = require('create-react-class');
|
13 | var RCTTestModule = require('NativeModules').TestModule;
|
14 | var React = require('react-native');
|
15 | var {
|
16 | Text,
|
17 | View,
|
18 | } = React;
|
19 |
|
20 | var IntegrationTestHarnessTest = createClass({
|
21 | propTypes: {
|
22 | shouldThrow: PropTypes.bool,
|
23 | waitOneFrame: PropTypes.bool,
|
24 | },
|
25 |
|
26 | getInitialState() {
|
27 | return {
|
28 | done: false,
|
29 | };
|
30 | },
|
31 |
|
32 | componentDidMount() {
|
33 | if (this.props.waitOneFrame) {
|
34 | requestAnimationFrame(this.runTest);
|
35 | } else {
|
36 | this.runTest();
|
37 | }
|
38 | },
|
39 |
|
40 | runTest() {
|
41 | if (this.props.shouldThrow) {
|
42 | throw new Error('Throwing error because shouldThrow');
|
43 | }
|
44 | if (!RCTTestModule) {
|
45 | throw new Error('RCTTestModule is not registered.');
|
46 | } else if (!RCTTestModule.markTestCompleted) {
|
47 | throw new Error('RCTTestModule.markTestCompleted not defined.');
|
48 | }
|
49 | this.setState({done: true}, RCTTestModule.markTestCompleted);
|
50 | },
|
51 |
|
52 | render() {
|
53 | return (
|
54 | <View style={{backgroundColor: 'white', padding: 40}}>
|
55 | <Text>
|
56 | {this.constructor.displayName + ': '}
|
57 | {this.state.done ? 'Done' : 'Testing...'}
|
58 | </Text>
|
59 | </View>
|
60 | );
|
61 | }
|
62 | });
|
63 |
|
64 | module.exports = IntegrationTestHarnessTest;
|