I run a UI test where I need to test an asynchronous function using the waitForExpectations
API.
I get this error:
"NSInternalInconsistencyException", "API Violation - A Call Waiting to Wait without Waiting."
I really do not understand, since I created the expectation correctly.
Also, there seems to be a bug in the documentation: according to the API documentation expectation(description:)
, but the compiler will not agree with this, instead I need to use XCTestExpectation()
to create it.
func testExample() { XCTAssertTrue(state == .STATE_NOT_READY) let exp1 = XCTestExpectation() let queue = DispatchQueue(label: "net.tech4freedom.AppTest") let delay: DispatchTimeInterval = .seconds((2)) queue.asyncAfter(deadline: .now() + delay) { XCTAssertTrue(true) exp1.fulfill() } self.waitForExpectations(timeout: 4){ [weak self] error in print("X: async expectation") XCTAssertTrue(true) } self.waitForExpectations(timeout: 10.0, handler: nil) }
source share