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
56 lines (49 loc) · 1.31 KB
/
createTestCaseComponent.js
File metadata and controls
56 lines (49 loc) · 1.31 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
51
52
53
54
55
56
"use strict";
var React = require("react-native");
var { DeviceEventEmitter } = require("react-native");
var NativeCodePush = React.NativeModules.CodePush;
// RCTTestModule is not implemented yet for RN Android.
var RCTTestModule = React.NativeModules.TestModule || {};
var {
Text,
View,
} = React;
function createTestCaseComponent(displayName, description, setUp, runTest, passAfterRun = true) {
var 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 ? "Done" : "Testing..."}
</Text>
</View>
);
}
});
TestCaseComponent.displayName = displayName;
TestCaseComponent.description = description;
return TestCaseComponent;
}
module.exports = createTestCaseComponent;