UNPKG

1.58 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 */
9'use strict';
10import PropTypes from 'prop-types';
11
12var createClass = require('create-react-class');
13var RCTTestModule = require('NativeModules').TestModule;
14var React = require('react-native');
15var {
16 Text,
17 View,
18} = React;
19
20var 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
64module.exports = IntegrationTestHarnessTest;