Skip to content

Instantly share code, notes, and snippets.

@otaviocc
Created August 21, 2022 18:29
Show Gist options
  • Save otaviocc/00af82bf750b581ba9b065f0bad0b4ef to your computer and use it in GitHub Desktop.
Save otaviocc/00af82bf750b581ba9b065f0bad0b4ef to your computer and use it in GitHub Desktop.
XCTestCase Wait Until
extension XCTestCase {
func waitUntil(
timeout: TimeInterval = 1,
isInverted: Bool = false,
fulfillmentCount: Int = 1,
block: @escaping (@escaping () -> Void) -> Void
) {
let expectation = expectation(
description: "isInverted: \(isInverted), fulfillmentCount: \(fulfillmentCount)"
)
expectation.isInverted = isInverted
expectation.expectedFulfillmentCount = fulfillmentCount
block(expectation.fulfill)
wait(for: [expectation], timeout: timeout)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment