Created
October 19, 2019 21:40
-
-
Save descorp/3f1fbead209ab791ff7af9d4458d4bf8 to your computer and use it in GitHub Desktop.
This file contains 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
extension XCTest { | |
func expectToEventually(_ test: @autoclosure () -> Bool, timeout: TimeInterval = 1.0, message: String = "") { | |
let runLoop = RunLoop.current | |
let timeoutDate = Date(timeIntervalSinceNow: timeout) | |
repeat { | |
// 1 | |
if test() { | |
return | |
} | |
// 2 | |
runLoop.run(until: Date(timeIntervalSinceNow: 0.01)) | |
} while Date().compare(timeoutDate) == .orderedAscending // 3 | |
// 4 | |
XCTFail(message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment