Quick / Nimble

A Matcher Framework for Swift and Objective-C
https://quick.github.io/Nimble/documentation/nimble/
Apache License 2.0
4.81k stars 598 forks source link

Unable to verify that an async function eventually sends an NSNotification. #1013

Open younata opened 1 year ago

younata commented 1 year ago

The following test does not work:

func asyncFunctionPostingNotification() async {
    // ...
    NotificationCenter.default.post(...)
}

expect { await asyncFunctionPostingNotification() }.to(postNotification(...))

Because of how async expectations are implemented, the Expression (await asyncFunctionPostingNotification() } is called before the matcher (postNotification(...)) is called. This is a result of the approach we take with async expressions, where the expression is evaluated, then the result of the expression is passed into the matcher.

Perhaps we should take this as a chance to rethink how AsyncExpectation works, and provide full end-to-end support for async expressions. We could use something approaching the current method as a fallback for existing, non-async matchers.