Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Alexander-Ignition/9dde0e2ae254019a890f0395c1b47f46 to your computer and use it in GitHub Desktop.
Save Alexander-Ignition/9dde0e2ae254019a890f0395c1b47f46 to your computer and use it in GitHub Desktop.
XCTestCase+URLSessionDataTask
import XCTest
extension XCTestCase {
func expectationDataTask(dataTask: NSURLSessionDataTask) -> XCTestExpectation {
dataTask.resume()
let expectation = keyValueObservingExpectationForObject(dataTask, keyPath: "state") { _, _ in
return dataTask.state == .Completed || dataTask.state == .Canceling
}
return expectation
}
func waitForExpectationDataTask(dataTask: NSURLSessionDataTask) -> XCTestExpectation {
let expectation = expectationDataTask(dataTask)
let timeout = dataTask.currentRequest?.timeoutInterval ?? 65
waitForExpectationsWithTimeout(timeout, handler: nil)
return expectation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment