Skip to content

Conversation

@tomconnell-wf
Copy link

@tomconnell-wf tomconnell-wf commented May 3, 2024

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:

  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)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@tomconnell-wf tomconnell-wf force-pushed the add_trace_to_when_stateError branch from df3f363 to cad4c40 Compare May 3, 2024 21:42
@tomconnell-wf tomconnell-wf changed the title Store the stack for a when creation, so we can know which one isn't complete. 🪧 fix - Store the stack for a when creation, so we can know which one isn't complete. 🪧 Jun 12, 2024
@tomconnell-wf tomconnell-wf force-pushed the add_trace_to_when_stateError branch from 89d430e to b9bfc91 Compare June 12, 2024 16:03
@tomconnell-wf tomconnell-wf marked this pull request as ready for review June 12, 2024 16:03
@tomconnell-wf tomconnell-wf requested a review from felangel as a code owner June 12, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants