Files
react-native/packages/rn-tester/IntegrationTests/SyncMethodTest.js
T
Fabrizio Cucci 1a1714300e Migrate rn-tester/IntegrationTests/SyncMethodTest.js to function components (#48696)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48696

As per title.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D68152294

fbshipit-source-id: 16b36d4702159528fe99c1a7d54c2c7b58d30349
2025-01-15 06:11:21 -08:00

50 lines
1.3 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 strict-local
*/
'use strict';
import * as React from 'react';
import {useEffect} from 'react';
import {NativeModules, View} from 'react-native';
const {TestModule, RNTesterTestModule} = NativeModules;
function SyncMethodTest(): React.Node {
useEffect(() => {
if (
RNTesterTestModule.echoString('test string value') !== 'test string value'
) {
throw new Error('Something wrong with echoString sync method');
}
if (RNTesterTestModule.methodThatReturnsNil() != null) {
throw new Error('Something wrong with methodThatReturnsNil sync method');
}
let response;
RNTesterTestModule.methodThatCallsCallbackWithString('test', echo => {
response = echo;
});
requestAnimationFrame(() => {
if (response === 'test') {
TestModule.markTestCompleted();
} else {
throw new Error(
'Something wrong with methodThatCallsCallbackWithString sync method, ' +
'got response ' +
JSON.stringify(response),
);
}
});
}, []);
return <View />;
}
export default SyncMethodTest;