Skip to content
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

Store the stack for a when creation, so we can know which one isn't complete. 🪧 #238

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

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 - 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

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.

None yet

1 participant