Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created March 30, 2017 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/22c2330c513e0e2139120f127d2295c8 to your computer and use it in GitHub Desktop.
Save chelseatroy/22c2330c513e0e2139120f127d2295c8 to your computer and use it in GitHub Desktop.
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