2017-04-27 21:49:50 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-04-27 21:49:50 +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.
|
2017-04-27 21:49:50 +03:00
|
|
|
*
|
2018-05-11 01:44:55 +03:00
|
|
|
* @format
|
2018-08-09 18:32:04 +03:00
|
|
|
* @flow strict-local
|
2017-04-27 21:49:50 +03:00
|
|
|
*/
|
2018-05-11 01:44:55 +03:00
|
|
|
|
2017-04-27 21:49:50 +03:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-14 10:09:36 +03:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const {View} = ReactNative;
|
2017-04-27 21:49:50 +03:00
|
|
|
|
2018-05-11 01:44:55 +03:00
|
|
|
const {TestModule, RNTesterTestModule} = ReactNative.NativeModules;
|
2017-04-27 21:49:50 +03:00
|
|
|
|
2019-11-21 20:38:13 +03:00
|
|
|
class SyncMethodTest extends React.Component<{...}> {
|
2017-04-27 21:49:50 +03:00
|
|
|
componentDidMount() {
|
2018-05-11 01:44:55 +03:00
|
|
|
if (
|
|
|
|
RNTesterTestModule.echoString('test string value') !== 'test string value'
|
|
|
|
) {
|
2019-04-08 19:10:44 +03:00
|
|
|
throw new Error('Something wrong with echoString sync method');
|
2017-04-27 21:49:50 +03:00
|
|
|
}
|
2017-05-06 06:50:47 +03:00
|
|
|
if (RNTesterTestModule.methodThatReturnsNil() != null) {
|
2019-04-08 19:10:44 +03:00
|
|
|
throw new Error('Something wrong with methodThatReturnsNil sync method');
|
2017-04-27 21:49:50 +03:00
|
|
|
}
|
2019-04-08 19:10:44 +03:00
|
|
|
let response;
|
2020-03-25 07:35:58 +03:00
|
|
|
RNTesterTestModule.methodThatCallsCallbackWithString('test', echo => {
|
2019-04-08 19:10:44 +03:00
|
|
|
response = echo;
|
|
|
|
});
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
if (response === 'test') {
|
|
|
|
TestModule.markTestCompleted();
|
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
'Something wrong with methodThatCallsCallbackWithString sync method, ' +
|
|
|
|
'got response ' +
|
|
|
|
JSON.stringify(response),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2017-04-27 21:49:50 +03:00
|
|
|
}
|
|
|
|
|
2017-08-18 04:36:54 +03:00
|
|
|
render(): React.Node {
|
2017-04-27 21:49:50 +03:00
|
|
|
return <View />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SyncMethodTest.displayName = 'SyncMethodTest';
|
|
|
|
|
|
|
|
module.exports = SyncMethodTest;
|