diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m index 08a1a1e37fec81..337a223fd84bb1 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m @@ -107,12 +107,36 @@ - (void)invalidate @end +// Define a module that is not explicitly registered with RCT_EXPORT_MODULE +@interface UnregisteredTestModule : NSObject + +@property (nonatomic, assign) BOOL testMethodCalled; + +@end + +@implementation UnregisteredTestModule + +@synthesize methodQueue = _methodQueue; + ++ (NSString *)moduleName +{ + return @"UnregisteredTestModule"; +} + +RCT_EXPORT_METHOD(testMethod) +{ + _testMethodCalled = YES; +} + +@end + @interface RCTBridgeTests : XCTestCase { RCTBridge *_bridge; __weak TestExecutor *_jsExecutor; BOOL _testMethodCalled; + UnregisteredTestModule *_unregisteredTestModule; } @end @@ -126,8 +150,9 @@ - (void)setUp { [super setUp]; + _unregisteredTestModule = [UnregisteredTestModule new]; _bridge = [[RCTBridge alloc] initWithBundleURL:nil - moduleProvider:^{ return @[self]; } + moduleProvider:^{ return @[self, _unregisteredTestModule]; } launchOptions:nil]; _bridge.executorClass = [TestExecutor class]; @@ -211,6 +236,37 @@ - (void)testCallNativeMethod }); } +- (void)testCallUnregisteredModuleMethod +{ + NSString *injectedStuff; + RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); + XCTAssertNotNil(injectedStuff); + + __block NSNumber *testModuleID = nil; + __block NSNumber *testMethodID = nil; + + NSArray *remoteModuleConfig = RCTJSONParse(injectedStuff, NULL)[@"remoteModuleConfig"]; + [remoteModuleConfig enumerateObjectsUsingBlock:^(id moduleConfig, NSUInteger i, __unused BOOL *stop) { + if ([moduleConfig isKindOfClass:[NSArray class]] && [moduleConfig[0] isEqualToString:@"UnregisteredTestModule"]) { + testModuleID = @(i); + testMethodID = @([moduleConfig[1] indexOfObject:@"testMethod"]); + *stop = YES; + } + }]; + + XCTAssertNotNil(testModuleID); + XCTAssertNotNil(testMethodID); + + NSArray *args = @[]; + NSArray *buffer = @[@[testModuleID], @[testMethodID], @[args]]; + + [_bridge.batchedBridge handleBuffer:buffer]; + + dispatch_sync(_unregisteredTestModule.methodQueue, ^{ + XCTAssertTrue(_unregisteredTestModule.testMethodCalled); + }); +} + - (void)DISABLED_testBadArgumentsCount { //NSArray *bufferWithMissingArgument = @[@[@1], @[@0], @[@[@1234, @5678, @"stringy", @{@"a": @1}/*, @42*/]], @[], @1234567];