-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFile.swift
54 lines (44 loc) · 1.45 KB
/
File.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// File.swift
// UITestKit
//
// Created by Eric Internicola on 11/5/17.
//
import XCTest
class BaseIntegrationTest: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
MockingjayProtocol.removeAllStubs()
super.tearDown()
}
/// Waits for the desired amount of time (and frees up the UI thread while it waits)
///
/// - Parameter timeout: The length of time to wait for
func waitForDuration(_ timeout: TimeInterval) {
waitForCondition({return false}, timeout: timeout)
}
/// Waits for the provided condition block to evaluate to true, or the timeout amount of time to elapse.
///
/// - Parameters:
/// - condition: The block to evaluate for truthy/falsy.
/// - timeout: The length of time to stop querying the block and just return false.
/// - Returns: True if the block evaluated truthy in the allotted time, false otherwise.
@discardableResult
func waitForCondition(_ condition: () -> Bool, timeout: TimeInterval) -> Bool {
var done = false
let startTime = NSDate()
while !done {
RunLoop.current.run(mode: .defaultRunLoopMode, before: Date(timeIntervalSinceNow: 0.1))
done = condition()
if done {
break
}
if -startTime.timeIntervalSinceNow > timeout {
return false
}
}
return true
}
}