feat: enhance test example to use dependency injection, useEffect, and scope.launch()#2845
Open
mkienenb wants to merge 3 commits intoJetBrains:masterfrom
Conversation
feat: replace hardcoded topics with an injected topicService.
Collaborator
|
@mkienenb could you, please, describe the goal? |
Collaborator
|
Non-strict contracts aren't welcome in examples :( |
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.
The current example React testing code is too minimal to reflect real-world usage patterns, which makes it harder to validate and demonstrate correct behavior in production-like scenarios.
Enhancing the examples to include:
Dependency Injection
Allows components to receive services (API clients, stores, etc.) in a testable way. This avoids hidden globals and makes it possible to substitute mocks/fakes cleanly in tests.
useEffectusageMost non-trivial React components rely on side effects (data loading, subscriptions, initialization). Including
useEffectensures examples cover lifecycle behavior and async updates, which are often the source of bugs.Avoiding
MainScopeusage in tests / using test-controlled coroutine scopeUsing
MainScope(or other default, unmanaged scopes) inside components makes tests unreliable because:Together, these changes make the examples:
This will significantly improve the usefulness of the examples as a reference for users building non-trivial applications.
.... And it will also make it easier to provide a reproducible environment for the coroutines issue, but that's not enough justification by itself.