When using XCTestExpectation, is there a difference between writing XCTAssert in sink or after wait?
My example:
let exp = expectation(description: "test")
repository.delete(id: "2")
.sink { [unowned self] in
print("in sink closure")
XCTAssertEqual(repository.object.count, 2)
XCTAssertFalse(repository.object.contains { $0.id == "2" })
exp.fulfill()
}
.store(in: &cancellables)
wait(for: [exp], timeout: 1.0)
print("after wait")
XCTAssertEqual(repository.object.count, 2)
XCTAssertFalse(repository.object.contains { $0.id == "2" })
XCTAssert in sink succeeds, but XCTAssert after wait fails. So I thought the code after wait would be executed without waiting for wait. However, the console outputs the following in the following order
in sink closure
after wait
Why does XCTAssert fail after wait?