mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 23:59:42 +08:00
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
"use strict";
|
|
|
|
import React from "react-native";
|
|
import { DeviceEventEmitter, Text, View } from "react-native";
|
|
let NativeCodePush = React.NativeModules.CodePush;
|
|
|
|
// RCTTestModule is not implemented yet for RN Android.
|
|
let RCTTestModule = React.NativeModules.TestModule || {};
|
|
|
|
function createTestCaseComponent(displayName, description, setUp, runTest, passAfterRun = true) {
|
|
let TestCaseComponent = React.createClass({
|
|
propTypes: {
|
|
shouldThrow: React.PropTypes.bool,
|
|
waitOneFrame: React.PropTypes.bool,
|
|
},
|
|
getInitialState() {
|
|
return {
|
|
done: false,
|
|
};
|
|
},
|
|
componentDidMount() {
|
|
setUp()
|
|
.then(runTest)
|
|
.then(() => {
|
|
if (passAfterRun) {
|
|
this.setState({done: true}, RCTTestModule.markTestCompleted);
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.error(err);
|
|
throw err;
|
|
});
|
|
},
|
|
render() {
|
|
return (
|
|
<View style={{backgroundColor: "white", padding: 40}}>
|
|
<Text>
|
|
{this.state.done ? "Test Passed!" : "Testing..."}
|
|
</Text>
|
|
</View>
|
|
);
|
|
}
|
|
});
|
|
|
|
TestCaseComponent.displayName = displayName;
|
|
TestCaseComponent.description = description;
|
|
|
|
return TestCaseComponent;
|
|
}
|
|
|
|
export default createTestCaseComponent; |