-
Notifications
You must be signed in to change notification settings - Fork 93
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
Adding support for verify(...).timeout(ms) #97
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #97 +/- ##
=========================================
+ Coverage 94.9% 95.01% +0.1%
=========================================
Files 34 34
Lines 609 622 +13
Branches 70 72 +2
=========================================
+ Hits 578 591 +13
Misses 22 22
Partials 9 9
Continue to review full report at Codecov.
|
ec505ac
to
d81029e
Compare
Rebased on latest |
Hi, sorry for my late response. Thanks for contributing but this API looks little bit strange. While Also I don't know if this should be part of mocking framework. I think this can be handled by external function. @bendykowski what do you think? |
An external function would look something like this?
This means two lines of setup, and one line of actually waiting. So it's more typing. It's also backwards to do most of the waiting related things in the setup phase, not in the verification phase, like this:
One thing to think about is that if you are doing it in the setup phase, like above, there is no way to set mocked return values. If your test is overriding the return value, the waiting setup will fail.
It becomes very complicated to allow tests to override the return value, but still be able to wait for the method invocation. You cannot use |
The problem is the return type. Besides, it looks like all methods of |
ping |
Another possible syntax could be something like: await timeout(mockedFoo.getBar(), 1000); The downside would be that the syntax for verifying a call has been done synchronously or asynchronously would be very different. |
Pushed another commit updating the readme |
I would love seeing this feature added. I see the point of not using the verify syntax. So going with the suggested timeout would be fine. But I also have another idea. Why not
|
Maybe similar API as Java mockito? |
Adding support for waiting until an asynchronous method is invoked. This is useful when mocking an API that doesn't use promises that you can await, but uses callback functions.
Inspired by: http://static.javadoc.io/org.mockito/mockito-core/2.16.0/org/mockito/Mockito.html#verification_timeout
Example:
This code will wait until foo.getBar() was invoked, and fail if it isn't invoked within the given time.