mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 20:25:33 +08:00
Move JS integration tests to root folder
Reviewed By: mkonicek Differential Revision: D2658454 fb-gh-sync-id: b639ea995411a7e43903264318b5fca4d2f1e9f7
This commit is contained in:
committed by
facebook-github-bot-9
parent
7a794cc72b
commit
a027218641
67
IntegrationTests/IntegrationTestHarnessTest.js
Normal file
67
IntegrationTests/IntegrationTestHarnessTest.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var requestAnimationFrame = require('requestAnimationFrame');
|
||||
var React = require('react-native');
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
var { TestModule } = React.NativeModules;
|
||||
|
||||
var IntegrationTestHarnessTest = React.createClass({
|
||||
propTypes: {
|
||||
shouldThrow: React.PropTypes.bool,
|
||||
waitOneFrame: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
done: false,
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.waitOneFrame) {
|
||||
requestAnimationFrame(this.runTest);
|
||||
} else {
|
||||
this.runTest();
|
||||
}
|
||||
},
|
||||
|
||||
runTest() {
|
||||
if (this.props.shouldThrow) {
|
||||
throw new Error('Throwing error because shouldThrow');
|
||||
}
|
||||
if (!TestModule) {
|
||||
throw new Error('RCTTestModule is not registered.');
|
||||
} else if (!TestModule.markTestCompleted) {
|
||||
throw new Error('RCTTestModule.markTestCompleted not defined.');
|
||||
}
|
||||
this.setState({done: true}, TestModule.markTestCompleted);
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
IntegrationTestHarnessTest.displayName = 'IntegrationTestHarnessTest';
|
||||
|
||||
module.exports = IntegrationTestHarnessTest;
|
||||
Reference in New Issue
Block a user