Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing Asynchronous Calls with FutureKit
class MockSession: URLSession {
var completionHandler: ((Data?, URLResponse?, Error?) -> Void)?
var request: URLRequest?
let stubbedDataTask: MockURLSessionDataTask = MockURLSessionDataTask()
override func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask {
self.completionHandler = completionHandler
self.request = request
return stubbedDataTask
}
}
class MockURLSessionDataTask: URLSessionDataTask {
var resumeWasCalled: Bool = false
override func resume() {
resumeWasCalled = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment