2015-06-10 00:26:49 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-06-10 00:26:49 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03: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-10 00:26:49 +03:00
|
|
|
*
|
2018-05-11 01:44:55 +03:00
|
|
|
* @format
|
2015-11-18 19:25:30 +03:00
|
|
|
* @flow
|
2015-06-10 00:26:49 +03:00
|
|
|
*/
|
2018-05-11 01:44:55 +03:00
|
|
|
|
2015-06-10 00:26:49 +03:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-14 10:09:36 +03:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const {View} = ReactNative;
|
|
|
|
const {TestModule} = ReactNative.NativeModules;
|
2015-06-10 00:26:49 +03:00
|
|
|
|
2019-11-21 20:38:13 +03:00
|
|
|
class PromiseTest extends React.Component<{...}> {
|
2019-08-09 20:06:53 +03:00
|
|
|
shouldResolve: boolean = false;
|
|
|
|
shouldReject: boolean = false;
|
|
|
|
shouldSucceedAsync: boolean = false;
|
|
|
|
shouldThrowAsync: boolean = false;
|
2015-06-10 00:26:49 +03:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
Promise.all([
|
|
|
|
this.testShouldResolve(),
|
|
|
|
this.testShouldReject(),
|
2015-08-04 15:23:31 +03:00
|
|
|
this.testShouldSucceedAsync(),
|
|
|
|
this.testShouldThrowAsync(),
|
2018-05-11 01:44:55 +03:00
|
|
|
]).then(() =>
|
|
|
|
TestModule.markTestPassed(
|
|
|
|
this.shouldResolve &&
|
|
|
|
this.shouldReject &&
|
|
|
|
this.shouldSucceedAsync &&
|
|
|
|
this.shouldThrowAsync,
|
|
|
|
),
|
|
|
|
);
|
2016-07-26 11:00:02 +03:00
|
|
|
}
|
2015-06-10 00:26:49 +03:00
|
|
|
|
2019-08-09 20:06:53 +03:00
|
|
|
testShouldResolve: () => any = () => {
|
2018-05-11 01:44:55 +03:00
|
|
|
return TestModule.shouldResolve()
|
|
|
|
.then(() => (this.shouldResolve = true))
|
|
|
|
.catch(() => (this.shouldResolve = false));
|
2016-07-26 11:00:02 +03:00
|
|
|
};
|
2015-06-10 00:26:49 +03:00
|
|
|
|
2019-08-09 20:06:53 +03:00
|
|
|
testShouldReject: () => any = () => {
|
2018-05-11 01:44:55 +03:00
|
|
|
return TestModule.shouldReject()
|
|
|
|
.then(() => (this.shouldReject = false))
|
|
|
|
.catch(() => (this.shouldReject = true));
|
2016-07-26 11:00:02 +03:00
|
|
|
};
|
2015-06-10 00:26:49 +03:00
|
|
|
|
2019-08-09 20:06:53 +03:00
|
|
|
testShouldSucceedAsync: () => Promise<any> = async (): Promise<any> => {
|
2015-08-04 15:23:31 +03:00
|
|
|
try {
|
2015-11-18 19:25:30 +03:00
|
|
|
await TestModule.shouldResolve();
|
2015-08-04 15:23:31 +03:00
|
|
|
this.shouldSucceedAsync = true;
|
|
|
|
} catch (e) {
|
|
|
|
this.shouldSucceedAsync = false;
|
|
|
|
}
|
2016-07-26 11:00:02 +03:00
|
|
|
};
|
2015-08-04 15:23:31 +03:00
|
|
|
|
2019-08-09 20:06:53 +03:00
|
|
|
testShouldThrowAsync: () => Promise<any> = async (): Promise<any> => {
|
2015-08-04 15:23:31 +03:00
|
|
|
try {
|
2015-11-18 19:25:30 +03:00
|
|
|
await TestModule.shouldReject();
|
2015-08-04 15:23:31 +03:00
|
|
|
this.shouldThrowAsync = false;
|
|
|
|
} catch (e) {
|
|
|
|
this.shouldThrowAsync = true;
|
|
|
|
}
|
2016-07-26 11:00:02 +03:00
|
|
|
};
|
2015-08-04 15:23:31 +03:00
|
|
|
|
2017-08-18 04:36:54 +03:00
|
|
|
render(): React.Node {
|
2016-04-09 06:36:40 +03:00
|
|
|
return <View />;
|
2015-06-10 00:26:49 +03:00
|
|
|
}
|
2016-07-26 11:00:02 +03:00
|
|
|
}
|
2015-06-10 00:26:49 +03:00
|
|
|
|
2015-06-24 05:12:51 +03:00
|
|
|
PromiseTest.displayName = 'PromiseTest';
|
|
|
|
|
2015-06-10 00:26:49 +03:00
|
|
|
module.exports = PromiseTest;
|