mockingbird icon indicating copy to clipboard operation
mockingbird copied to clipboard

Stubbing base class of an extension.

Open carlos-evolutive opened this issue 2 years ago • 0 comments

I have a simple extension to UIDevice that I wanted to test:

public extension UIDevice {
    func isPad() -> Bool {
         return self.userInterfaceIdiom == .pad
    }
}

Mi test goes as follows:

func testIsPad() throws {
    let device = mock(UIDevice.self)

    // Stubbing
    given(device.userInterfaceIdiom).willReturn(.pad)

    print("value: \(device.userInterfaceIdiom)")
    print(device.isPad())
    
    XCTAssertTrue(device.isPad())
}

The thing is that this compiles just fine but it does not work, is there any way to accomplish this or it is just not possible, sorry for the novice question...

carlos-evolutive avatar Apr 28 '22 14:04 carlos-evolutive