mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add GTest utility methods to test C++ Turbo Module EventEmitters (#54060)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54060 Changelog: [Internal] Adds a test case to assert Turbo Module eventEmitter properties in GTests Reviewed By: javache Differential Revision: D83280050 fbshipit-source-id: 6c05d779c38a6988f07a11ccb436429aa1a12975
This commit is contained in:
committed by
meta-codesync[bot]
parent
0fd24c75a1
commit
6d7a93f2b1
@@ -8,7 +8,6 @@
|
||||
#include <NativeCxxModuleExample/NativeCxxModuleExample.h>
|
||||
#include <ReactCommon/TurboModuleTestFixture.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
@@ -172,4 +171,25 @@ TEST_F(
|
||||
EXPECT_EQ(module_->getWithWithOptionalArgs(*runtime_, false), false);
|
||||
}
|
||||
|
||||
TEST_F(NativeCxxModuleExampleTests, VoidFunEmitsEvents) {
|
||||
int onPressCalled = 0;
|
||||
std::string onClickCalled;
|
||||
auto onPressSubscription = addEventEmitterListener<>(
|
||||
*runtime_, "onPress", [&]() { onPressCalled++; });
|
||||
addEventEmitterListener<std::string>(
|
||||
*runtime_, "onClick", [&](const std::string& event) {
|
||||
onClickCalled = event;
|
||||
});
|
||||
module_->voidFunc(*runtime_);
|
||||
jsInvoker_->flushQueue();
|
||||
EXPECT_EQ(onPressCalled, 1);
|
||||
EXPECT_EQ(onClickCalled, "value from callback on click!");
|
||||
|
||||
onPressSubscription.remove();
|
||||
jsInvoker_->flushQueue();
|
||||
|
||||
module_->voidFunc(*runtime_);
|
||||
jsInvoker_->flushQueue();
|
||||
EXPECT_EQ(onPressCalled, 1);
|
||||
}
|
||||
} // namespace facebook::react
|
||||
|
||||
Reference in New Issue
Block a user