mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d1153ff468
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48697 As per title. Changelog: [Internal] Reviewed By: rshest Differential Revision: D68152416 fbshipit-source-id: 32d6d503ed119f8d7e5b9c139060b61ef44b8768
87 lines
1.9 KiB
JavaScript
87 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import * as React from 'react';
|
|
import {useEffect, useRef} from 'react';
|
|
import {NativeModules, View} from 'react-native';
|
|
|
|
const {TestModule} = NativeModules;
|
|
|
|
function PromiseTest(): React.Node {
|
|
const shouldResolve = useRef(false);
|
|
const shouldReject = useRef(false);
|
|
const shouldSucceedAsync = useRef(false);
|
|
const shouldThrowAsync = useRef(false);
|
|
|
|
const testShouldResolve = () => {
|
|
return TestModule.shouldResolve()
|
|
.then(() => {
|
|
shouldResolve.current = true;
|
|
})
|
|
.catch(() => {
|
|
shouldResolve.current = false;
|
|
});
|
|
};
|
|
|
|
const testShouldReject = () => {
|
|
return TestModule.shouldReject()
|
|
.then(() => {
|
|
shouldReject.current = false;
|
|
})
|
|
.catch(() => {
|
|
shouldReject.current = true;
|
|
});
|
|
};
|
|
|
|
const testShouldSucceedAsync = async () => {
|
|
try {
|
|
await TestModule.shouldResolve();
|
|
shouldSucceedAsync.current = true;
|
|
} catch (e) {
|
|
shouldSucceedAsync.current = false;
|
|
}
|
|
};
|
|
|
|
const testShouldThrowAsync = async () => {
|
|
try {
|
|
await TestModule.shouldReject();
|
|
shouldThrowAsync.current = false;
|
|
} catch (e) {
|
|
shouldThrowAsync.current = true;
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
async function runTests() {
|
|
await Promise.all([
|
|
testShouldResolve(),
|
|
testShouldReject(),
|
|
testShouldSucceedAsync(),
|
|
testShouldThrowAsync(),
|
|
]);
|
|
|
|
TestModule.markTestPassed(
|
|
shouldResolve.current &&
|
|
shouldReject.current &&
|
|
shouldSucceedAsync.current &&
|
|
shouldThrowAsync.current,
|
|
);
|
|
}
|
|
|
|
runTests().catch(console.error);
|
|
}, []);
|
|
|
|
return <View />;
|
|
}
|
|
|
|
export default PromiseTest;
|