.
Код: Выделить всё
@Test mutating func testSomeFunction() async {
let someVar = SomeStruct(
with: "Foo",
name: "Bar",
id: 1
)
result = .failure(.failedToFetch)
try? await Task.sleep(nanoseconds: 2_000_000_000)
await confirmation("someVar data") { confirm in
someVar.dataForObject(with: 15) { result in
switch result {
case .success:
Issue.record("Fetch unexpectedly succeeded")
case let .failure(error):
#expect(error == .failedToFetch)
}
confirm()
}
}
}
< /code>
my xctest выглядел так < /p>
func testSomeFunction() {
let someVar = SomeStruct(
with: "Foo",
name: "Bar",
id: 1
)
self.result = .failure(.failedToFetch)
XCTAssertNotNil(someVar)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
let expectation = XCTestExpectation(description: "someVar data")
someVar.dataForObject(with: 15) { result in
switch result {
case .success:
XCTFail("Fetch unexpectedly succeeded")
case let .failure(error):
XCTAssertNotNil(error)
}
}
XCTWaiter().wait(for: [expectation], timeout: 10)
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... ed-0-times
Мобильная версия