Swift: Quick/Nimble running async test shows error: 'InvalidNimbleAPIUsage', reason: 'expect(...).toEventually(...) can only run on the main thread.'
Asked Answered
C

0

7

I'm implementing a test case using Quick/Nimble making network request (URLRequest) but I'm getting this error:

 *** Terminating app due to uncaught exception 'InvalidNimbleAPIUsage', reason: 'expect(...).toEventually(...) can only run on the main thread.'

This is my test case:

 expect(someVar).toEventually(equal("bar"), timeout: 0.2, pollInterval: 0.1, description: "time")

If change my implementation:

DispatchQueue.main.async {
    expect(someVar).toEventually(equal("bar"), timeout: 0.2, pollInterval: 0.1, description: "time")
}

I get this error:

*** Terminating app due to uncaught exception 'InvalidNimbleAPIUsage', reason: 'Nested async expectations are not allowed to avoid creating flaky tests.

Any of you has an idea how can make this test case to work using Quick/Nimble ?

I'll really appreciate your help

Crossbreed answered 10/9, 2019 at 19:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.