From eac320c8d774f64f66969a564b2897175f415051 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 23 Oct 2026 09:49:22 -0400 Subject: [PATCH] test: the notifications view model is built inside each test, after the test Main dispatcher is set (#6275) Built as a property initializer it ran at class construction, before MainDispatcherExtension's beforeEach, so viewModelScope.launch in init hit the missing Main dispatcher. Its uncaught exceptions also failed the next coroutine test in the JVM (RetryTransientIoTest). Co-Authored-By: Claude Opus 5.5 --- .../minstrel/notifications/ui/NotificationsViewModelTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/app/src/test/java/com/fabledsword/minstrel/notifications/ui/NotificationsViewModelTest.kt b/android/app/src/test/java/com/fabledsword/minstrel/notifications/ui/NotificationsViewModelTest.kt index 36be8d97..afa33564 100644 --- a/android/app/src/test/java/com/fabledsword/minstrel/notifications/ui/NotificationsViewModelTest.kt +++ b/android/app/src/test/java/com/fabledsword/minstrel/notifications/ui/NotificationsViewModelTest.kt @@ -24,7 +24,8 @@ class NotificationsViewModelTest { private val network: NetworkStatusController = mockk { every { state } returns MutableStateFlow(ServerHealth.Healthy) } - private val viewModel = NotificationsViewModel(repository, network) + // Lazy: built inside each test, after the extension has swapped in the test Main dispatcher. + private val viewModel by lazy { NotificationsViewModel(repository, network) } private fun row(id: String, read: Boolean) = CachedNotificationEntity( id = id,