Function forward​ToSuper()
public func forwardToSuper() -> ForwardingContext
Forward calls for a specific declaration to the superclass.
Use willForwardToSuper
on class mock declarations to call the superclass implementation.
Superclass forwarding persists until removed with clearStubs
or shadowed by a forwarding
target that was added afterwards.
class Bird {
let name: String
init(name: String) { self.name = name }
}
// `BirdMock` subclasses `Bird`
let bird: BirdMock = mock(Bird.self).initialize(name: "Ryan")
given(bird.name) ~> forwardToSuper()
print(bird.name) // Prints "Ryan"
The mocked type must be a class. Adding superclass forwarding to mocked protocol declarations is a no-op.
// Not a class
protocol AbstractBird {
var name: String { get }
}
let bird = mock(AbstractBird.self)
given(bird.name) ~> forwardToSuper()
print(bird.name) // Error: Missing stubbed implementation