mirror of https://github.com/oxen-io/session-ios
parent
8fcb61353e
commit
25ae8ca3ba
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@
|
|||||||
|
import XCTest
|
||||||
|
|
||||||
|
extension XCTestCase {
|
||||||
|
|
||||||
|
/// Simple helper for asynchronous testing.
|
||||||
|
/// Usage in XCTestCase method:
|
||||||
|
/// func testSomething() {
|
||||||
|
/// doAsyncThings()
|
||||||
|
/// eventually {
|
||||||
|
/// /* XCTAssert goes here... */
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// Cloure won't execute until timeout is met. You need to pass in an
|
||||||
|
/// timeout long enough for your asynchronous process to finish, if it's
|
||||||
|
/// expected to take more than the default 0.1 second.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - timeout: amout of time in seconds to wait before executing the
|
||||||
|
/// closure.
|
||||||
|
/// - closure: a closure to execute when `timeout` seconds has passed
|
||||||
|
func eventually(timeout: TimeInterval = 0.1, closure: @escaping () -> Void) {
|
||||||
|
let expectation = self.expectation(description: "")
|
||||||
|
expectation.fulfillAfter(timeout)
|
||||||
|
self.waitForExpectations(timeout: 60) { _ in
|
||||||
|
closure()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension XCTestExpectation {
|
||||||
|
|
||||||
|
/// Call `fulfill()` after some time.
|
||||||
|
///
|
||||||
|
/// - Parameter time: amout of time after which `fulfill()` will be called.
|
||||||
|
func fulfillAfter(_ time: TimeInterval) {
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + time) {
|
||||||
|
self.fulfill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue