Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions packages/react-native/React/Tests/Mounting/RCTBridgeProxyTests.mm
Original file line number Diff line number Diff line change
@@ -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 <React/RCTBridgeModule.h>
#import <React/RCTBridgeProxy.h>
#import <React/RCTBundleManager.h>
#import <XCTest/XCTest.h>

// 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
Loading