Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eventually does not support async methods #297

Open
1 task done
jacobhzen opened this issue Apr 18, 2022 · 2 comments
Open
1 task done

Eventually does not support async methods #297

jacobhzen opened this issue Apr 18, 2022 · 2 comments
Labels
enhancement Feature request or improvement

Comments

@jacobhzen
Copy link

New Feature Request Checklist

Overview

Looking to use eventually to verify the execution of async methods:

Task {
  guard bird.canFly else { return }
  await bird.fly()
}

eventually {
  verify(bird.canFly).wasCalled()
  verify(await bird.fly()).wasCalled()
}

waitForExpectations(timeout: 1)
@jacobhzen jacobhzen added the enhancement Feature request or improvement label Apr 18, 2022
@MincDev
Copy link

MincDev commented Jan 9, 2023

Any idea if this is going to be supported?

@nicholaslythall
Copy link

I have found a temporary workaround, until this is officially supported.

  1. Mark the test as async
  2. Await the Mockable declaration outside of the eventually block
  3. Call verify inside eventually with the already obtained declaration
func test_asyncEventuallyWorkaround() async -> {
    // Casting to Mockable is required to disambiguate between the real method and the given/verify DSL method
    let someCall = await someMock.someFunc() as Mockable
    eventually {
        verify(someCall).wasCalled()
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or improvement
Projects
None yet
Development

No branches or pull requests

3 participants