2015-06-09 21:26:49 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2015-11-18 16:25:30 +00:00
|
|
|
* @flow
|
2015-06-09 21:26:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
|
|
|
var { View } = ReactNative;
|
|
|
|
var { TestModule } = ReactNative.NativeModules;
|
2015-06-09 21:26:49 +00:00
|
|
|
|
|
|
|
var PromiseTest = React.createClass({
|
|
|
|
shouldResolve: false,
|
|
|
|
shouldReject: false,
|
2015-08-04 12:23:31 +00:00
|
|
|
shouldSucceedAsync: false,
|
|
|
|
shouldThrowAsync: false,
|
2015-06-09 21:26:49 +00:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
Promise.all([
|
|
|
|
this.testShouldResolve(),
|
|
|
|
this.testShouldReject(),
|
2015-08-04 12:23:31 +00:00
|
|
|
this.testShouldSucceedAsync(),
|
|
|
|
this.testShouldThrowAsync(),
|
2015-11-18 16:25:30 +00:00
|
|
|
]).then(() => TestModule.markTestPassed(
|
2015-08-04 12:23:31 +00:00
|
|
|
this.shouldResolve && this.shouldReject &&
|
|
|
|
this.shouldSucceedAsync && this.shouldThrowAsync
|
2015-06-09 21:26:49 +00:00
|
|
|
));
|
|
|
|
},
|
|
|
|
|
|
|
|
testShouldResolve() {
|
2015-11-18 16:25:30 +00:00
|
|
|
return TestModule
|
2015-06-09 21:26:49 +00:00
|
|
|
.shouldResolve()
|
|
|
|
.then(() => this.shouldResolve = true)
|
|
|
|
.catch(() => this.shouldResolve = false);
|
|
|
|
},
|
|
|
|
|
|
|
|
testShouldReject() {
|
2015-11-18 16:25:30 +00:00
|
|
|
return TestModule
|
2015-06-09 21:26:49 +00:00
|
|
|
.shouldReject()
|
|
|
|
.then(() => this.shouldReject = false)
|
|
|
|
.catch(() => this.shouldReject = true);
|
|
|
|
},
|
|
|
|
|
2016-05-25 01:20:12 +00:00
|
|
|
async testShouldSucceedAsync() : Promise<any> {
|
2015-08-04 12:23:31 +00:00
|
|
|
try {
|
2015-11-18 16:25:30 +00:00
|
|
|
await TestModule.shouldResolve();
|
2015-08-04 12:23:31 +00:00
|
|
|
this.shouldSucceedAsync = true;
|
|
|
|
} catch (e) {
|
|
|
|
this.shouldSucceedAsync = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-25 01:20:12 +00:00
|
|
|
async testShouldThrowAsync() : Promise<any> {
|
2015-08-04 12:23:31 +00:00
|
|
|
try {
|
2015-11-18 16:25:30 +00:00
|
|
|
await TestModule.shouldReject();
|
2015-08-04 12:23:31 +00:00
|
|
|
this.shouldThrowAsync = false;
|
|
|
|
} catch (e) {
|
|
|
|
this.shouldThrowAsync = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-25 01:20:12 +00:00
|
|
|
render() : ReactElement<any> {
|
2016-04-09 03:36:40 +00:00
|
|
|
return <View />;
|
2015-06-09 21:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-06-24 02:12:51 +00:00
|
|
|
PromiseTest.displayName = 'PromiseTest';
|
|
|
|
|
2015-06-09 21:26:49 +00:00
|
|
|
module.exports = PromiseTest;
|