ios - How to test method that runs async on main thread? -


i have method:

func update(with process: presentableprocess) {     presentableprocess = process     if isviewloaded {         dispatchqueue.main.async { [weak self] in             //do sth on main thread         }     } } 

and test:

func testpreferredcontentsizewhentitleexist() {     let process = presentableprocess(title: "title")     sut.update(with: process)      xctassertequalwithaccuracy(sut.preferredcontentsize, 95, accuracy: 10) } 

it doesnt work, because runs on main thread... avoid adding completion block in update(with) pass test.

i'm afraid need use completion block. test asynchronous functions use expectations

let expectation = expectation(description: "expectation")  dostuffwithcompletion() {     expectation.fulfill() }  waitforexpectations(timeout: 10) { error in     // } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -