1

I am writing a test to confirm the if a method shifts the focus to next textField. I tried the code from iOS unit test: How to set/update/examine firstResponder?. But it fails.

- (void)testFocusMovedToYearField {
  UIWindow *window = [[UIWindow alloc] init];
  [window addSubview:self.dateCell.txtDay];
  [window addSubview:self.dateCell.txtYear];   
  [self.dateCell completionBlockHelper];
  [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]]; 
  XCTAssertTrue([self.kioskDateCell.txtYear isFirstResponder]);
}

The function completionBlockHelper contains the code to make the txtYear become first responder.

Any suggestions will be helpful.

Community
  • 1
  • 1
user3453784
  • 593
  • 3
  • 9
  • 19
  • This works for me. Are you sure that `self.dateCell.txtYear` is not `nil`? Are you sure `completionBlockHelper` is getting invoked? Try stepping through the test to try and figure out what's going on. – Steve Wilford Aug 12 '15 at 07:47
  • Yes, pretty sure `self.dateCell.txtYear` is not nil and `completionBlockHelper` is invoked as well. I also tried replacing `[self.dateCell completionBlockHelper]` with `[self.dateCell.txtYear becomeFirstResponder]` just to check if that works but no luck. – user3453784 Aug 12 '15 at 13:14
  • any update? I am experiencing the same issue. Tried putting in a fake dummy view to no avail – Charlton Provatas Oct 26 '17 at 21:37

1 Answers1

1

The window needs to become the key window. In Swift: window.makeKeyAndVisible()

Gabriel
  • 613
  • 7
  • 12