A WhenCall that hasn't completed yet can be a real pain to track down, unless you know to just keep scrolling up past all the cascading failures - the failures happen at the next time when() is called, which could be in a different test. (I suppose that one could make the case that the tests should resetMocktailState, but we came over from Mockito, so lots of places do not.) This change stores the current stack during WhenCall creation, so this error can show that stack, making it trivial to find the problematic mock/test.
I didn't add any until testing, because, after thinking about it, the test would have basically tested if stack actually got set, thus testing StackTrace.current by proxy. That didn't seem valuable to me. I'm happy to add something like that though, if desired.
Before Error:
Bad state: Cannot call `when` within a stub response
dart:sdk_internal throw_
package:mocktail/src/mocktail.dart 227:5 get when
skaar_client/connection_manager_test.dart 448:33 new
skaar_client/connection_manager_test.dart 420:23 <fn>
After Error:
Bad state: Cannot call `when` within a stub response, Mock: _MockCerberusService, MemberName: Symbol("ping"), RegistrationStack:
dart:sdk_internal 125441:30 get current
package:mocktail/src/mocktail.dart 295:66 new
package:mocktail/src/mocktail.dart 114:19 noSuchMethod
skaar_client/connection_manager_test.dart 74:29 <fn> // This is where the when call was created
package:mocktail/src/mocktail.dart 232:8 <fn>
skaar_client/connection_manager_test.dart 74:43 <fn>
dart:sdk_internal 36040:7 _async
skaar_client/connection_manager_test.dart 70:9 <fn>
package:test_api/src/backend/declarer.dart 215:19 <fn>
dart:sdk_internal 31931:9 <fn>
dart:sdk_internal throw_
package:mocktail/src/mocktail.dart 227:5 get when
skaar_client/connection_manager_test.dart 448:33 new
skaar_client/connection_manager_test.dart 420:23 <fn>
Type of Change
[ ] ✨ New feature (non-breaking change which adds functionality)
[x] 🛠️ Bug fix (non-breaking change which fixes an issue)
[ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
Status
IN DEVELOPMENT
Breaking Changes
NO
Description
A WhenCall that hasn't completed yet can be a real pain to track down, unless you know to just keep scrolling up past all the cascading failures - the failures happen at the next time
when()
is called, which could be in a different test. (I suppose that one could make the case that the tests should resetMocktailState, but we came over from Mockito, so lots of places do not.) This change stores the current stack during WhenCall creation, so this error can show that stack, making it trivial to find the problematic mock/test.I didn't add any until testing, because, after thinking about it, the test would have basically tested if stack actually got set, thus testing StackTrace.current by proxy. That didn't seem valuable to me. I'm happy to add something like that though, if desired.
Before Error:
After Error:
Type of Change