Files
react-native/packages/rn-tester/IntegrationTests/PromiseTest.js
Tim Yung 1977dd6596 RN: Sort Pragmas in Headers (#51554)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51554

Sorts pragma directives file headers in React Native.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D75264593

fbshipit-source-id: 9e4b253dd0fc94dc2fc469d7114b93a8aae305f4
2025-05-22 21:18:53 -07:00

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.
*
* @flow
* @format
*/
'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;