mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
test RCTInstance initialization (#37860)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37860 Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D46547013 fbshipit-source-id: 2b1593799ce2b5d29e7ea6df4373ff6c92b51065
This commit is contained in:
committed by
Facebook GitHub Bot
parent
be2b0e2d8a
commit
a4dae044df
@@ -40,10 +40,18 @@ static ShimRCTInstance *shimmedRCTInstance;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[shimmedRCTInstance reset];
|
||||
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testStart
|
||||
{
|
||||
[_subject start];
|
||||
OCMVerify(OCMTimes(1), [_mockHostDelegate hostDidStart:_subject]);
|
||||
XCTAssertEqual(shimmedRCTInstance.initCount, 1);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,4 +8,9 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ShimRCTInstance : NSObject
|
||||
|
||||
@property (assign) int initCount;
|
||||
|
||||
- (void)reset;
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,20 +11,34 @@
|
||||
|
||||
#import "RCTSwizzleHelpers.h"
|
||||
|
||||
static __weak ShimRCTInstance *weakShim = nil;
|
||||
|
||||
@implementation ShimRCTInstance
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_initCount = 0;
|
||||
RCTSwizzleInstanceSelector(
|
||||
[RCTInstance class],
|
||||
[ShimRCTInstance class],
|
||||
@selector(initWithDelegate:
|
||||
jsEngineInstance:bundleManager:turboModuleManagerDelegate:onInitialBundleLoad:moduleRegistry:));
|
||||
weakShim = self;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)reset
|
||||
{
|
||||
RCTSwizzleInstanceSelector(
|
||||
[RCTInstance class],
|
||||
[ShimRCTInstance class],
|
||||
@selector(initWithDelegate:
|
||||
jsEngineInstance:bundleManager:turboModuleManagerDelegate:onInitialBundleLoad:moduleRegistry:));
|
||||
_initCount = 0;
|
||||
}
|
||||
|
||||
- (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
|
||||
jsEngineInstance:(std::shared_ptr<facebook::react::JSEngineInstance>)jsEngineInstance
|
||||
bundleManager:(RCTBundleManager *)bundleManager
|
||||
@@ -32,6 +46,7 @@
|
||||
onInitialBundleLoad:(RCTInstanceInitialBundleLoadCompletionBlock)onInitialBundleLoad
|
||||
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
|
||||
{
|
||||
weakShim.initCount++;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user