Skip to content

Commit 0d715cd

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
add unit tests for EventTarget (facebook#41596)
Summary: Pull Request resolved: facebook#41596 changelog: [internal] Reviewed By: rshest Differential Revision: D51499449 fbshipit-source-id: 782108edf24af1c91d77c664bc496b466995621e
1 parent a6964b3 commit 0d715cd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <gtest/gtest.h>
9+
#include <hermes/hermes.h>
10+
#include <react/renderer/core/EventTarget.h>
11+
#include <react/renderer/core/InstanceHandle.h>
12+
13+
using namespace facebook;
14+
using namespace facebook::react;
15+
16+
TEST(EventTargetTests, getInstanceHandle) {
17+
auto runtime = facebook::hermes::makeHermesRuntime();
18+
auto object = jsi::Object(*runtime);
19+
auto instanceHandle = std::make_shared<InstanceHandle>(
20+
*runtime, jsi::Value(*runtime, object), 1);
21+
22+
EXPECT_EQ(instanceHandle->getTag(), 1);
23+
24+
auto eventTarget = EventTarget(std::move(instanceHandle));
25+
26+
EXPECT_EQ(eventTarget.getTag(), 1);
27+
28+
EXPECT_TRUE(eventTarget.getInstanceHandle(*runtime).isNull());
29+
30+
eventTarget.retain(*runtime);
31+
32+
EXPECT_TRUE(eventTarget.getInstanceHandle(*runtime).isNull());
33+
34+
eventTarget.setEnabled(true);
35+
36+
eventTarget.retain(*runtime);
37+
38+
EXPECT_FALSE(eventTarget.getInstanceHandle(*runtime).isNull());
39+
40+
eventTarget.release(*runtime);
41+
42+
EXPECT_TRUE(eventTarget.getInstanceHandle(*runtime).isNull());
43+
}

0 commit comments

Comments
 (0)