Browse Source

Fix flaky unit tests (#4997)

Yogev Ben David 5 years ago
parent
commit
189f5593f7
No account linked to committer's email address
1 changed files with 10 additions and 7 deletions
  1. 10
    7
      lib/ios/ReactNativeNavigationTests/RNNLayoutManagerTest.m

+ 10
- 7
lib/ios/ReactNativeNavigationTests/RNNLayoutManagerTest.m View File

@@ -45,17 +45,20 @@
45 45
 }
46 46
 
47 47
 - (void)testFindComponentShouldReturnModalFromFirstWindow {
48
+	UIViewController* rootViewController = [OCMockObject partialMockForObject:[UIViewController new]];
49
+	
48 50
 	UIViewController* modal = _vc1;
49
-	OCMStub([_vc2 presentedViewController]).andReturn(modal);
50
-	_firstWindow.rootViewController = _vc2;
51
+	OCMStub([rootViewController presentedViewController]).andReturn(modal);
52
+	_firstWindow.rootViewController = rootViewController;
51 53
 	UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
52 54
 	XCTAssertEqual(resultVC, modal);
53 55
 }
54 56
 
55 57
 - (void)testFindComponentShouldReturnModalFromSecondWindow {
58
+	UIViewController* rootViewController = [OCMockObject partialMockForObject:[UIViewController new]];
56 59
 	UIViewController* modal = _vc1;
57
-	OCMStub([_vc2 presentedViewController]).andReturn(modal);
58
-	_secondWindow.rootViewController = _vc2;
60
+	OCMStub([rootViewController presentedViewController]).andReturn(modal);
61
+	_secondWindow.rootViewController = rootViewController;
59 62
 	UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
60 63
 	XCTAssertEqual(resultVC, modal);
61 64
 }
@@ -70,7 +73,7 @@
70 73
 	UINavigationController* nvc = [[UINavigationController alloc] init];
71 74
 	[nvc setViewControllers:@[_vc1, _vc2, _vc3]];
72 75
 	_secondWindow.rootViewController = nvc;
73
-
76
+	
74 77
 	UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc3"];
75 78
 	XCTAssertEqual(resultVC, _vc3);
76 79
 }
@@ -79,8 +82,8 @@
79 82
 	RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
80 83
 	layoutInfo.componentId = componentId;
81 84
 	
82
-	UIViewController* vc = [OCMockObject partialMockForObject:[UIViewController new]];
83
-	OCMStub([vc layoutInfo]).andReturn(layoutInfo);
85
+	UIViewController* vc = [UIViewController new];
86
+	vc.layoutInfo = layoutInfo;
84 87
 	
85 88
 	return vc;
86 89
 }