Flutter Mock Amplify using Mockito

Viewed 247

I am trying to write a test for this code, yeah it's not perfect...does anyone know if there is a way to mock the Amplify.Hub.listen call that can answer with a MockSubscribtion perhaps? I tried using this class MockSubscribtion extends Mock implements StreamSubscription<dynamic> {} but but obviously that wouldn't work. There are some relevant examples here... does any one know if there's a way to simply mock this call without stubbing out all the transient dependencies?

/// Emits [User.empty] if the user is not authenticated.
  Stream<User> get user async* {
    subscription = Amplify.Hub.listen([HubChannel.Auth], (hubEvent) async* {
      if (hubEvent.eventName == 'SIGNED_IN') {
        try {
          var amplifyUser = await _authenticationInterface.getCurrentUser();
          var currentUser = User(
              username: amplifyUser.username,
              id: amplifyUser.userId,
              firstname: null,
              lastname: null,
              grade: null);
          yield currentUser;
        } on Exception {
          throw GetUserFailure();
        }
      } else {
        subscription.cancel();
      }
    });
  }
0 Answers
Related