fix(mocktail): clearer error for multi-mock verify closure - #270
Open
realmeylisdev wants to merge 1 commit into
Open
fix(mocktail): clearer error for multi-mock verify closure#270realmeylisdev wants to merge 1 commit into
realmeylisdev wants to merge 1 commit into
Conversation
…ck invocations
When a `verify(() { ... })` closure invokes more than one mock member
(e.g. passing another mock's getter as an argument), mocktail previously
failed with "Used on a non-mocktail object" — a message intended for the
no-mock case. Reporters have mistaken this for an invocation-counting bug.
- Split the fallback branch in `_makeVerify` so the message now names
the invocations that were recorded and points the user at the fix
(capture values into locals before the verify closure).
- Clear `_verifyCalls` on failure so a subsequent `verify(...)` isn't
blocked by the stale-state `StateError` in the entry check.
- Add a regression test covering both the new message and the
state-cleanup invariant.
Refs felangel#262
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Status
READY
Breaking Changes
NO
Description
When a
verify(() { ... })closure invokes more than one mock member — typically by passing a second mock's getter as an argument to the method being verified — mocktail currently fails with:That message is only accurate when the closure touched zero mocks. For the multi-invocation case, it's misleading and has led users to believe there's a bug in invocation counting (see #262).
Root cause: the fallback branch in
_makeVerifytreated_verifyCalls.length != 1as a single case. Splitting the branch lets us produce a diagnostic that names the actual problem.This PR:
_makeVerifyto distinguish_verifyCalls.isEmpty(non-mock object) from_verifyCalls.length > 1(multiple mock invocations inside the closure).verify(...)call._verifyCallson the failure path so a subsequentverify(...)isn't blocked by the entry-checkStateError— this previously required a manualreset()to recover.Before
After
Type of Change
Testing
verify_test.dart › should fail when closure invokes multiple mock memberscovers both the new message and the state-cleanup invariant.dart test— 221/221 passing.dart analyze— clean.Related
Refs #262 (does not fully close the issue — the reporter's case is a test-wiring error, not a library bug — but this PR removes the misleading message that contributed to the confusion).