@@ -327,5 +327,51 @@ void main() {
327327 verifyNever (mockClient.closeConnection);
328328 },
329329 );
330+
331+ testWidgets (
332+ 'should skip initial connectivity event to avoid race with connectUser' ,
333+ (tester) async {
334+ // Create a connectivity stream that will emit immediately on subscription
335+ final testConnectivityController = BehaviorSubject .seeded (
336+ [ConnectivityResult .mobile],
337+ );
338+
339+ // Set up for reconnection scenario
340+ when (
341+ () => mockClient.wsConnectionStatus,
342+ ).thenReturn (ConnectionStatus .disconnected);
343+
344+ // Clear any previous calls
345+ clearInteractions (mockClient);
346+
347+ // Arrange - pump widget with connectivity stream
348+ // The BehaviorSubject will emit [mobile] immediately on subscription
349+ // which should be skipped by skip(1)
350+ await tester.pumpWidget (
351+ MaterialApp (
352+ home: StreamChatCore (
353+ client: mockClient,
354+ connectivityStream: testConnectivityController.stream,
355+ child: const SizedBox (),
356+ ),
357+ ),
358+ );
359+ await tester.pumpAndSettle ();
360+
361+ // Assert - the initial event from BehaviorSubject should be skipped
362+ verifyNever (mockClient.closeConnection);
363+ verifyNever (mockClient.openConnection);
364+
365+ // Now emit a connectivity change (this is the 2nd event, won't be skipped)
366+ testConnectivityController.add ([ConnectivityResult .wifi]);
367+ await tester.pumpAndSettle ();
368+
369+ // Assert - second event should trigger reconnection
370+ verify (mockClient.closeConnection).called (1 );
371+ verify (mockClient.openConnection).called (1 );
372+
373+ testConnectivityController.close ();
374+ },
375+ );
330376 });
331377}
0 commit comments