@@ -287,25 +287,31 @@ class FirebaseAuthUIAuthStateTest {
287287 // Given initial idle state
288288 `when `(mockFirebaseAuth.currentUser).thenReturn(null )
289289
290- // When updating auth state internally
291- authUI.updateAuthState(AuthState .Loading (" Signing in..." ))
292-
293- // Then the flow should reflect the updated state
290+ // Start collecting the flow to capture initial state
294291 val states = mutableListOf<AuthState >()
295292 val job = launch {
296- authUI.authStateFlow().take(2 ).toList(states)
293+ authUI.authStateFlow().take(3 ).toList(states)
297294 }
298295
299- // Update state again
296+ // Wait for initial state to be collected
300297 delay(100 )
298+
299+ // When updating auth state internally
300+ authUI.updateAuthState(AuthState .Loading (" Signing in..." ))
301+
302+ // Wait for state update to propagate
303+ delay(100 )
304+
305+ // Update state again
301306 authUI.updateAuthState(AuthState .Cancelled )
302307
303308 job.join()
304309
305- // The first state should be Idle (initial), second should be Loading
306- assertThat(states[0 ]).isEqualTo(AuthState .Idle )
307- // Note: The internal state update may not be immediately visible in the flow
308- // because the auth state listener overrides it
310+ // Verify the emitted states
311+ assertThat(states).hasSize(3 )
312+ assertThat(states[0 ]).isEqualTo(AuthState .Idle ) // Initial state
313+ assertThat(states[1 ]).isInstanceOf(AuthState .Loading ::class .java) // After first update
314+ assertThat(states[2 ]).isEqualTo(AuthState .Cancelled ) // After second update
309315 }
310316
311317 // =============================================================================================
0 commit comments