Add device event emit test for the sample C++ TurboModule (#36278)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36278

[Changelog][Internal]

The diff creates a test clause for [TurboModule::emitDeviceEvent C++ API for TurboModules](https://www.internalfb.com/code/fbsource/[929870c905c8fe68cb330ce96bda7eb703bb6ae6]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h?lines=90), which can be seen in either Catalyst or RNTester.

Reviewed By: cipolleschi

Differential Revision: D43466327

fbshipit-source-id: ff4c111b4beaab72b13d2bd89ed03023c9c7b3cf
This commit is contained in:
Ruslan Shestopalyuk
2023-02-24 06:49:14 -08:00
committed by Facebook GitHub Bot
parent bf03e86bc7
commit e106a62b1a
4 changed files with 32 additions and 1 deletions
@@ -121,4 +121,19 @@ void NativeCxxModuleExample::voidFunc(jsi::Runtime &rt) {
// Nothing to do
}
void NativeCxxModuleExample::emitCustomDeviceEvent(
jsi::Runtime &rt,
jsi::String eventName) {
// Test emitting device events (RCTDeviceEventEmitter.emit) from C++
// TurboModule with arbitrary arguments
emitDeviceEvent(
rt,
eventName.utf8(rt).c_str(),
[](jsi::Runtime &rt, std::vector<jsi::Value> &args) {
args.emplace_back(jsi::Value(true));
args.emplace_back(jsi::Value(42));
args.emplace_back(jsi::String::createFromAscii(rt, "stringArg"));
});
}
} // namespace facebook::react