Skip to content

feat: enhance test example to use dependency injection, useEffect, and scope.launch()#2845

Open
mkienenb wants to merge 3 commits intoJetBrains:masterfrom
mkienenb:mlk/add-dependency-injection-and-coroutine-scopes-to-test-examples
Open

feat: enhance test example to use dependency injection, useEffect, and scope.launch()#2845
mkienenb wants to merge 3 commits intoJetBrains:masterfrom
mkienenb:mlk/add-dependency-injection-and-coroutine-scopes-to-test-examples

Conversation

@mkienenb
Copy link
Copy Markdown
Contributor

@mkienenb mkienenb commented Mar 17, 2026

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.

  • useEffect usage
    Most non-trivial React components rely on side effects (data loading, subscriptions, initialization). Including useEffect ensures examples cover lifecycle behavior and async updates, which are often the source of bugs.

  • Avoiding MainScope usage in tests / using test-controlled coroutine scope
    Using MainScope (or other default, unmanaged scopes) inside components makes tests unreliable because:

    • the lifecycle is not tied to the test, so coroutines may outlive the test or leak
    • tests cannot easily control or advance coroutine execution (for the case of runTest)

Together, these changes make the examples:

  • more representative of real applications
  • easier to test reliably

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.

feat: replace hardcoded topics with an injected topicService.
@turansky
Copy link
Copy Markdown
Collaborator

turansky commented Mar 17, 2026

@mkienenb could you, please, describe the goal?
Is it for coroutine's issue?

@turansky
Copy link
Copy Markdown
Collaborator

Non-strict contracts aren't welcome in examples :(
Discussion required

@turansky turansky self-requested a review March 17, 2026 21:42
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