2015-06-09 21:26:49 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-06-09 21:26:49 +00:00
|
|
|
*
|
2015-11-18 16:25:30 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule PromiseTest
|
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
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class PromiseTest extends React.Component<{}> {
|
2016-07-26 08:00:02 +00:00
|
|
|
shouldResolve = false;
|
|
|
|
shouldReject = false;
|
|
|
|
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
|
|
|
));
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-06-09 21:26:49 +00:00
|
|
|
|
2016-07-26 08:00:02 +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);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-06-09 21:26:49 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
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-07-26 08:00:02 +00:00
|
|
|
};
|
2015-06-09 21:26:49 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
testShouldSucceedAsync = async (): 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-07-26 08:00:02 +00:00
|
|
|
};
|
2015-08-04 12:23:31 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
testShouldThrowAsync = async (): 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-07-26 08:00:02 +00:00
|
|
|
};
|
2015-08-04 12:23:31 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
render(): React.Node {
|
2016-04-09 03:36:40 +00:00
|
|
|
return <View />;
|
2015-06-09 21:26:49 +00:00
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
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;
|