异步等待失败Swift 4 Alamofire

时间:2017-11-28 16:48:46

标签: swift xcode asynchronous alamofire

我在测试中得到了这段代码。代码执行错误"异步等待失败:超出超时......"。我本以为.fulfill()会启动但是它没有...任何关于如何在没有错误的情况下运行的想法?

func test_checkUpLoadFileIsThere_returnsString(){
    let expec = expectation(description: "photo viewer")
    let pvc = PhotoTakerViewController()
    let isImageThere = pvc.checkFileExsists("166220.jpg")
    waitForExpectations(timeout: 4, handler: {response in
        expec.fulfill()
        print("Expectation block")
    })

    XCTAssertEqual(isImageThere,"Found File : 166220.jpg","image should be there")
}

1 个答案:

答案 0 :(得分:0)

waitForExpectations之前您必须setContentView(R.layout.channel_activity)期望。现在你已经在等待的失败块中实现了,这根本不起作用。实际上,这段代码看起来并不是异步的,因此您根本不需要期望。如果它是异步的,则需要公开一个完成处理程序,以满足期望。

相关问题