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
|
|
|
*
|
2018-05-10 22:44:55 +00:00
|
|
|
* @format
|
2015-11-18 16:25:30 +00:00
|
|
|
* @flow
|
2015-06-09 21:26:49 +00:00
|
|
|
*/
|
2018-05-10 22:44:55 +00:00
|
|
|
|
2015-06-09 21:26:49 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-14 07:09:36 +00:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const {View} = ReactNative;
|
|
|
|
const {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(),
|
2018-05-10 22:44:55 +00:00
|
|
|
]).then(() =>
|
|
|
|
TestModule.markTestPassed(
|
|
|
|
this.shouldResolve &&
|
|
|
|
this.shouldReject &&
|
|
|
|
this.shouldSucceedAsync &&
|
|
|
|
this.shouldThrowAsync,
|
|
|
|
),
|
|
|
|
);
|
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 = () => {
|
2018-05-10 22:44:55 +00:00
|
|
|
return TestModule.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 = () => {
|
2018-05-10 22:44:55 +00:00
|
|
|
return TestModule.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;
|