forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTestCaseComponent.js
More file actions
50 lines (44 loc) · 1.27 KB
/
createTestCaseComponent.js
File metadata and controls
50 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
import React from "react-native";
import { DeviceEventEmitter, Text, View } from "react-native";
const NativeCodePush = React.NativeModules.CodePush;
// RCTTestModule is not implemented yet for RN Android.
const 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,
};
},
async componentDidMount() {
try {
await setUp();
await runTest();
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;