-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseTest.swift
41 lines (36 loc) · 1.01 KB
/
BaseTest.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
import Combine
import SwiftyBeaver
import XCTest
@testable import SubVTData
func initLog() {
let console = ConsoleDestination()
log.addDestination(console)
}
class BaseTest: XCTestCase {
private var cancellables: Set<AnyCancellable>!
override func setUp() {
initLog()
cancellables = []
}
func testServiceCall<T>(
publisher: ServiceResponsePublisher<T>,
timeoutSec: Double = 30,
afterCall: ((T?, APIError?) -> ())? = nil
) {
let expectation = self.expectation(description: "")
var error: APIError? = nil
var value: T? = nil
publisher
.sink { (response) in
if response.error != nil {
error = response.error
} else {
value = response.value!
}
expectation.fulfill()
}
.store(in: &cancellables)
waitForExpectations(timeout: timeoutSec)
afterCall?(value, error)
}
}