Reputation: 11
Ive been unit testing ReactiveCocoa Signals and Producers using XCTest expectations for a project im working on. For one some reason (I suspect after a pod update) my tests started failing and SignalProducer events are returning the interrupted value and never actually sending the successful value. If I set breakpoints everything seems to work fine in the actual task its just when it gets to the observer lifecycle where i dont see the value passed back. Using XCode 9.4.1 ReactiveCocoa (8.0.0) ReactiveSwift (4.0.0) Result (4.0.0)
let signalExpectation = self.expectation(description: "Signal Expectation")
let aSut = SignalProducer<Data,WXClientError> { observer, _ in
let task = URLSession.shared.dataTask(with: url!) { (data, URLResponse, Error) in if let Error = Error {
observer.send(error: WXClientError.webFailure(description: Error.localizedDescription))
} else if let httpResponse = URLResponse as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
observer.send(value:data!)
}
}
}
task.resume()
}
let testObserver = Signal<Data,WXClientError>.Observer{ (event) in
switch event {
case let .value(v):
print("Test Observation value = \(v)")
signalExpectation.fulfill()
case let .failed(error):
print("Test Observation error = \(error)")
case .completed:
print("Test Observation completed")
case .interrupted:
print("Test Observation interrupted")
}
}
aSut.start(testObserver)
self.waitForExpectations(timeout: 5.0, handler:nil)
Upvotes: 1
Views: 551