【发布时间】:2022-08-04 00:27:20
【问题描述】:
到目前为止,我一直在使用 Combine 和 PointFree TestScheduler https://github.com/pointfreeco/combine-schedulers 在我的测试中“控制时间”。
我可以提出请求,然后在过程中的某些点断言值而不会遇到任何麻烦。
例子...
func testFetchContentSuccess() {
let queue = TestSchedulerOf<DispatchQueue>(now: .init(.now()))
let sut = sut(queue: queue.eraseToAnyScheduler())
XCTAssertEqual(sut.content, .notAsked)
sut.fetchContent()
XCTAssertEqual(sut.content, .loading) // this would be impossible without a TestScheulder as the mock endpoint would return immediately.
queue.advance() // this is what I\'m looking for from async await
assertSnapshot(matching: sut.content, as: .dump)
}
有没有办法用异步等待做类似的事情?
标签: swift async-await combine