...

/

Solution: Testing ShoppingCartCubit

Solution: Testing ShoppingCartCubit

View the solution for testing the ShoppingCartCubit.

We hope that the exercise was simple! It’s time to see a possible solution to the exercise.

Mocking ShoppingCartCubit

Mocking the ShoppingCartCubit is done by extending the MockCubit class provided to us by the bloc_test library.

Press + to interact
class MockShoppingCartCubit extends MockCubit<ShoppingCartState>
implements ShoppingCartCubit {}

Implementing whenListen()

Press + to interact
ShoppingCartCubit shoppingCartCubit = MockShoppingCartCubit();
whenListen(
shoppingCartCubit,
Stream.fromIterable([
ShoppingCartUpdated(shoppingCart),
ShoppingCartUpdated(shoppingCart2)
]),
initialState: ShoppingCartInitial());
  • Line 1: This creates a MockShoppingCartCubit instance called shoppingCartCubit. ...

Access this course and 1400+ top-rated courses and projects.