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