diff --git a/packages/react-native/React/Tests/Mounting/RCTBridgeProxyTests.mm b/packages/react-native/React/Tests/Mounting/RCTBridgeProxyTests.mm new file mode 100644 index 00000000000..72cd24fa564 --- /dev/null +++ b/packages/react-native/React/Tests/Mounting/RCTBridgeProxyTests.mm @@ -0,0 +1,61 @@ +/* + * 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. + */ + +#import +#import +#import +#import + +// Not declared in RCTBridgeProxy.h, but callers that treat the bridge proxy as a +// legacy bridge send it; without an implementation the NSProxy throws. +@interface RCTBridgeProxy (RCTBridgeProxyTests) +- (id)object; +@end + +@interface RCTBridgeProxyTests : XCTestCase +@end + +@implementation RCTBridgeProxyTests { + RCTBridgeProxy *_bridgeProxy; + // The bridge proxy only stores the runtime pointer; it is never dereferenced here. + int _fakeRuntime; +} + +- (void)setUp +{ + [super setUp]; + + _bridgeProxy = [[RCTBridgeProxy alloc] initWithViewRegistry:[RCTViewRegistry new] + moduleRegistry:[RCTModuleRegistry new] + bundleManager:[RCTBundleManager new] + callableJSModules:[RCTCallableJSModules new] + dispatchToJSThread:^(dispatch_block_t block) { + } + registerSegmentWithId:^(NSNumber *segmentId, NSString *path) { + } + runtime:&_fakeRuntime + launchOptions:nil]; +} + +- (void)tearDown +{ + _bridgeProxy = nil; + + [super tearDown]; +} + +// XCTest assertion macros use variadic reporting and catch exceptions by value. +// NOLINTBEGIN(cppcoreguidelines-pro-type-vararg, misc-throw-by-value-catch-by-reference) +- (void)testObjectReturnsTheBridgeProxyInsteadOfThrowing +{ + id object = nil; + XCTAssertNoThrow(object = [_bridgeProxy object]); + XCTAssertEqual(object, _bridgeProxy); +} +// NOLINTEND(cppcoreguidelines-pro-type-vararg, misc-throw-by-value-catch-by-reference) + +@end