Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
Add a test for RCTBridgeModules that aren't auto-exported
Browse files Browse the repository at this point in the history
Summary:Adds a test so that people can create RCTBridgeModules that aren't auto-exported. This is useful for when you have more than one RCTBridge and want a module to be exposed in one but not the other.

RCTBridge/RCTBatchedBridge already supports this functionality; this diff adds a test so that it doesn't break.
Closes facebook#6424

Differential Revision: D3044959

Pulled By: nicklockwood

fb-gh-sync-id: f8977249b1bf4023e704be6422ad77372d8f1714
shipit-source-id: f8977249b1bf4023e704be6422ad77372d8f1714
  • Loading branch information
ide authored and Facebook Github Bot 5 committed Mar 14, 2016
1 parent bcd3c02 commit 9a8ac9d
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,36 @@ - (void)invalidate

@end

// Define a module that is not explicitly registered with RCT_EXPORT_MODULE
@interface UnregisteredTestModule : NSObject <RCTBridgeModule>

@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 <RCTBridgeModule>
{
RCTBridge *_bridge;
__weak TestExecutor *_jsExecutor;

BOOL _testMethodCalled;
UnregisteredTestModule *_unregisteredTestModule;
}
@end

Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 9a8ac9d

Please sign in to comment.