mockolo
mockolo copied to clipboard
Allow Computed Properties that return Self
Computed properties that return Self
also return Self
in the mock.
/// @mockable
protocol FooRepository {
static var shared: Self { get }
}
I would like the mock class return.
final class FooRepositoryMock: FooRepository {
init() { }
static private(set) var sharedSetCallCount = 0
- static private var _shared: Self! { didSet { sharedSetCallCount += 1 } }
- static var shared: Self {
+ static private var _shared: FooRepositoryMock! { didSet { sharedSetCallCount += 1 } }
+ static var shared: FooRepositoryMock {
get { return _shared }
set { _shared = newValue }
}
}
Reference
- https://github.com/uber/mockolo/pull/118
Version
- Mockolo: 1.7.0
If it were Self
, would there be any problems?
@sidepelican Mock causes a compile error.
❌ .../OutputMocks.swift:99:99: stored property cannot have covariant 'Self' type
static private var _shared: Self! { didSet { sharedSetCallCount += 1 } }
^
❌ .../OutputMocks.swift:99:99: mutable property cannot have covariant 'Self' type
public static var shared: Self {
^