-
-
Save laevandus/fbf2abbad9b6a08a290bf50d982ab8ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class ImageLoaderTests: XCTestCase { | |
func testLoadingImageSuccessfully() { | |
execute(withTimeout: 5) { | |
let imageLoader = ImageLoader() | |
_ = try await imageLoader.loadImage(for: "identifier") | |
} | |
} | |
} | |
extension XCTestCase { | |
func execute(withTimeout timeout: TimeInterval, file: StaticString = #filePath, line: UInt = #line, workItem: @escaping () async throws -> Void) { | |
let expectation = expectation(description: "wait for async function") | |
var workItemError: Error? | |
let captureError = { workItemError = $0 } | |
let task = Task { | |
do { | |
try await workItem() | |
} | |
catch { | |
captureError(error) | |
} | |
expectation.fulfill() | |
} | |
waitForExpectations(timeout: timeout) { _ in | |
if let error = workItemError { | |
XCTFail("\(error)", file: file, line: line) | |
} | |
task.cancel() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment