2121#import " RCTJavaScriptExecutor.h"
2222#import " RCTUtils.h"
2323
24+
25+ #define RUN_RUNLOOP_WHILE (CONDITION ) \
26+ _Pragma (" clang diagnostic push" ) \
27+ _Pragma (" clang diagnostic ignored \" -Wshadow\" " ) \
28+ NSDate *timeout = [[NSDate date ] dateByAddingTimeInterval: 0.1 ]; \
29+ while ((CONDITION) && [timeout timeIntervalSinceNow ] > 0 ) { \
30+ [[NSRunLoop currentRunLoop ] runMode: NSDefaultRunLoopMode beforeDate: timeout]; \
31+ } \
32+ _Pragma (" clang diagnostic pop" )
33+
2434@interface TestExecutor : NSObject <RCTJavaScriptExecutor>
2535
2636@property (nonatomic , readonly , copy ) NSMutableDictionary <NSString *, id> *injectedStuff;
@@ -93,6 +103,8 @@ - (void)invalidate {}
93103@interface RCTBridgeTests : XCTestCase <RCTBridgeModule>
94104{
95105 RCTBridge *_bridge;
106+ __weak TestExecutor *_jsExecutor;
107+
96108 BOOL _testMethodCalled;
97109}
98110@end
@@ -112,35 +124,34 @@ - (void)setUp
112124 launchOptions: nil ];
113125
114126 _bridge.executorClass = [TestExecutor class ];
127+
115128 // Force to recreate the executor with the new class
116129 // - reload: doesn't work here since bridge hasn't loaded yet.
117130 [_bridge invalidate ];
118131 [_bridge setUp ];
132+
133+ _jsExecutor = [_bridge.batchedBridge valueForKey: @" javaScriptExecutor" ];
134+ XCTAssertNotNil (_jsExecutor);
119135}
120136
121137- (void )tearDown
122138{
123139 [super tearDown ];
124140
125- [_bridge invalidate ];
126141 _testMethodCalled = NO ;
127- }
128142
129- #define RUN_RUNLOOP_WHILE (CONDITION ) \
130- _Pragma (" clang diagnostic push" ) \
131- _Pragma (" clang diagnostic ignored \" -Wshadow\" " ) \
132- NSDate *timeout = [[NSDate date ] dateByAddingTimeInterval: 0.1 ]; \
133- while ((CONDITION) && [timeout timeIntervalSinceNow ] > 0 ) { \
134- [[NSRunLoop currentRunLoop ] runMode: NSDefaultRunLoopMode beforeDate: timeout]; \
135- } \
136- _Pragma (" clang diagnostic pop" )
143+ [_bridge invalidate ];
144+ _bridge = nil ;
145+
146+ RUN_RUNLOOP_WHILE (_jsExecutor != nil );
147+ XCTAssertNotNil (_jsExecutor);
148+ }
137149
138150- (void )testHookRegistration
139151{
140- TestExecutor *executor = [_bridge.batchedBridge valueForKey: @" _javaScriptExecutor" ];
141-
142152 NSString *injectedStuff;
143- RUN_RUNLOOP_WHILE (!(injectedStuff = executor.injectedStuff [@" __fbBatchedBridgeConfig" ]));
153+ RUN_RUNLOOP_WHILE (!(injectedStuff = _jsExecutor.injectedStuff [@" __fbBatchedBridgeConfig" ]));
154+ XCTAssertNotNil (injectedStuff);
144155
145156 __block NSNumber *testModuleID = nil ;
146157 __block NSDictionary <NSString *, id > *testConstants = nil ;
@@ -165,10 +176,9 @@ - (void)testHookRegistration
165176
166177- (void )testCallNativeMethod
167178{
168- TestExecutor *executor = [_bridge.batchedBridge valueForKey: @" _javaScriptExecutor" ];
169-
170179 NSString *injectedStuff;
171- RUN_RUNLOOP_WHILE (!(injectedStuff = executor.injectedStuff [@" __fbBatchedBridgeConfig" ]));
180+ RUN_RUNLOOP_WHILE (!(injectedStuff = _jsExecutor.injectedStuff [@" __fbBatchedBridgeConfig" ]));
181+ XCTAssertNotNil (injectedStuff);
172182
173183 __block NSNumber *testModuleID = nil ;
174184 __block NSNumber *testMethodID = nil ;
0 commit comments