Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobsapps/62e2e58fe335e74d4210d044b1e8bb83 to your computer and use it in GitHub Desktop.
Save jacobsapps/62e2e58fe335e74d4210d044b1e8bb83 to your computer and use it in GitHub Desktop.
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