Created
July 8, 2025 11:25
-
-
Save jacobsapps/62e2e58fe335e74d4210d044b1e8bb83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class MockAPI: API { | |
// mock result | |
public var stubFetchResponse: Result<[Model], Error>? | |
// deferred closure | |
public var didFetchData: (() -> Void)? | |
// what we assert | |
public private(set) var fetchDataWasCalled = false | |
// the actual mock function | |
public func fetchData() async throws -> [Model] { | |
defer { didFetchData?() } // called AFTER return | |
fetchDataWasCalled = true | |
return try stubFetchResponse.get() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment