0

I try to test my UIViewController when I set the title:

var sut: FloorPlanVC!

override func setUp() {

    let storyboard = UIStoryboard(name: “FloorPlan”, bundle: nil)
    sut = storyboard.instantiateInitialViewController() as! FloorPlanVC
    _ = sut.view
}

func testSetTitle() {
    sut.title = “Title” //1
    XCTAssertEqual(sut.navigationItem.title, “Title”) //2
}

Outputs 1 on console:

po sut.title //Title
po sut.navigationItem.title //Title

Outputs 2 on console:

po sut.title //Title
po sut.navigationItem.title //nil
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

1 Answers1

0

The issue that you are facing right now is similar to what some people asked with this question:

Changing navigation title programmatically

Your problem is in a test environment but I think you can relate to it. I personally see the issue of the whole set-up being in the test environment leading to you getting unexpected behavior. Check out the answers in the link I gave you, try out which one will work and also let me know. I was going to just copy them all but no point, you can click the link.

Dido
  • 358
  • 3
  • 17