diff --git a/local-cli/generator-ios/templates/app/AppDelegate.m b/local-cli/generator-ios/templates/app/AppDelegate.m index aa83b142388ff9..49055c1981a5b8 100644 --- a/local-cli/generator-ios/templates/app/AppDelegate.m +++ b/local-cli/generator-ios/templates/app/AppDelegate.m @@ -47,6 +47,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"<%= name %>" + initialProperties:nil launchOptions:launchOptions]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; diff --git a/local-cli/generator-ios/templates/tests/Tests.m b/local-cli/generator-ios/templates/tests/Tests.m index 818c17fb5f43d7..0f4d1bfae98844 100644 --- a/local-cli/generator-ios/templates/tests/Tests.m +++ b/local-cli/generator-ios/templates/tests/Tests.m @@ -10,8 +10,7 @@ #import #import -#import "RCTAssert.h" -#import "RCTRedBox.h" +#import "RCTLog.h" #import "RCTRootView.h" #define TIMEOUT_SECONDS 240 @@ -23,7 +22,6 @@ @interface <%= name %>Tests : XCTestCase @implementation <%= name %>Tests - - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test { if (test(view)) { @@ -37,18 +35,23 @@ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test return NO; } -- (void)testRendersWelcomeScreen { +- (void)testRendersWelcomeScreen +{ UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; BOOL foundElement = NO; - NSString *redboxError = nil; + + __block NSString *redboxError = nil; + RCTSetLogFunction(^(RCTLogLevel level, NSString *fileName, NSNumber *lineNumber, NSString *message) { + if (level >= RCTLogLevelError) { + redboxError = message; + } + }); while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - redboxError = [[RCTRedBox sharedInstance] currentErrorMessage]; - foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { return YES; @@ -57,6 +60,8 @@ - (void)testRendersWelcomeScreen { }]; } + RCTSetLogFunction(RCTDefaultLogFunction); + XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); }