Bloc: Migration to bloc_test 7 issue

Created on 30 Jul 2020  路  1Comment  路  Source: felangel/bloc

Hey, so I've got a Cubit that initialized with an initial "event" (FeedCubit(...)..fetchFeed(...)) , a couple of the tests used to look something like this:

blocTest<FeedCubit, FeedState>(
        'Increments Reaction count on React Event',
        build: () **async** {
          when(mockReactToPost(any)).thenAnswer(
            (_) async => Right(tPostReact),
          );

        when(mockGetFeed(any)).thenAnswer((_) async => Right(tFeed));
        when(mockGetFeedPosts(any)).thenAnswer((_) async => Right(feedPosts));

        **await feedCubit.fetchFeed(...);**

          return feedCubit;
        },
        act: (cubit) {
          cubit.reactToPost(
            feedId: tFeed.id,
            postId: tPostId,
            reactionId: tReactionId,
          );
        },
        expect: [
          FeedState.loaded(
            feed: tFeed,
            feedPosts: tFeedPostsIncremented,
            currentFeedView: CurrentFeedView.postListView,
          ),
        ],
      );

But now the build param doesn't take a Future. I've been trying a couple of different ways to get that initial "Event" to fire off but haven't been successful. Any help is appreciated 馃槃

Most helpful comment

Ok I read the docs 馃憤

Answer:

blocTest<FeedCubit, FeedState>(
        'Increments Reaction count on React Event',
        build: () {
          when(mockReactToPost(any)).thenAnswer(
            (_) async => Right(tPostReact),
          );
          return feedCubit
            ..emit(FeedLoaded(
              feed: tFeed,
              feedPosts: tFeedPosts,
              currentFeedView: CurrentFeedView.postListView,
            ));
        },
        act: (cubit) {
          cubit.reactToPost(
            feedId: tFeed.id,
            postId: tPostId,
            reactionId: tReactionId,
          );
        },
        expect: [
          FeedState.loaded(
            feed: tFeed,
            feedPosts: tFeedPostsIncremented,
            currentFeedView: CurrentFeedView.postListView,
          ),
        ],
      );

>All comments

Ok I read the docs 馃憤

Answer:

blocTest<FeedCubit, FeedState>(
        'Increments Reaction count on React Event',
        build: () {
          when(mockReactToPost(any)).thenAnswer(
            (_) async => Right(tPostReact),
          );
          return feedCubit
            ..emit(FeedLoaded(
              feed: tFeed,
              feedPosts: tFeedPosts,
              currentFeedView: CurrentFeedView.postListView,
            ));
        },
        act: (cubit) {
          cubit.reactToPost(
            feedId: tFeed.id,
            postId: tPostId,
            reactionId: tReactionId,
          );
        },
        expect: [
          FeedState.loaded(
            feed: tFeed,
            feedPosts: tFeedPostsIncremented,
            currentFeedView: CurrentFeedView.postListView,
          ),
        ],
      );
Was this page helpful?
0 / 5 - 0 ratings

Related issues

timtraversy picture timtraversy  路  3Comments

clicksocial picture clicksocial  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments

komapeb picture komapeb  路  3Comments

MahdiPishguy picture MahdiPishguy  路  3Comments