0

I am creating a test case, which tests if the delegate function didDisconnectwithError can be called, for TVIroom class. for that I need to pass the delegate function a blankempty TVI room object. However the delegate function does not accept nil values as inputs, and forced unwrapping is not allowed. How do I pass a TVIroom object to the delegate for testing, if it can't be nil? here is my code so far:

func testDisconnectCalled_usedWhileSwitching_AndwhileExplicitlyDisconnecting() {
        let delegate = RoomTestsDelegate()
        let room: TVIRoom? = nil
        let error: Error? = nil

        delegate.room(room, didDisconnectWithError: error)
        expect(delegate.notifiedAboutDidDisconnect).toEventually(beTrue(), timeout: 1)
    }
Arnold
  • 181
  • 3
  • 12

1 Answers1

0

If you check out the class reference of TVIRoom, it says that it is not recommended to be initialized by developers.

You could, however, create a mocked class similar to TVIRoom and set the delegate appropriately.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223