Fix return type error for unexpected method calls #518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This PR attempts to fix the issue of triggering a type error when an unexpected method call happens. Now it will return the correct type and let the code execution finish, so the predictions can be evaluated at the end of the test run.
See related comment here: #441 (comment)
PR which introduced the issue: #441
Relevant GitHub issues:
Example - Classes to test
Example - spec 1
The test passes: The only expectation we have is that method
bbb
should have been called with 26 and that happened so everything is fine.Note: This works with using
shouldBeCalled
beforedoStuff
as well.Example - spec 2
The test fails: The only expectation we have is that method
bbb
should NOT have been called with 26 and that happened so the test fails. (This also works using Argument::any() in the prediction)Note: This works with using
shouldNotBeCalled
beforedoStuff
as well.Example - spec 3
The test passes: There are no expectations so there is nothing that could fail here. So now the call to the method
bbb
is completely ignored, still not reported as an unexpected call. I am not sure if this is the desired behavior 🤔 since this basically eliminates the unexpected method call errors entirely. You will only see errors if you have a failed expectation.