Swift Quick/Nimble - Wait for predicate to match

4.9k Views Asked by At

I'm trying to convert the following block of code to Quick/Nimble with no success whatsoever

XCTWaiter().wait(for: [XCTNSPredicateExpectation(predicate: NSPredicate(format: "height == 0"), 
                                                 object: vc.myView.frame)], 
                 timeout: 1)

I tried the following but the test does not pass

waitUntil(timeout: 2) { done in
    expect(vc.myView.frame.height).to(equal(0))
    done()
}

Thx in advance for your help!

2

There are 2 best solutions below

0
On BEST ANSWER

You can also set the timeout globally, e.g. once your tests start, so it applies for all toEventually calls:

Nimble >= 9.0.0

Nimble.AsyncDefaults.timeout = .seconds(2)

Nimble < 9.0.0

Nimble.AsyncDefaults.Timeout = 2
0
On

I think "toEventually" is what you are looking for. Here is the example:

expect(vc.myView.frame.height).toEventually(equal(0), timeout: 2)

More to check here: https://github.com/Quick/Nimble#asynchronous-expectations