MockBloc<E, S> constructor

MockBloc<E, S>()

Extend or mixin this class to mark the implementation as a MockBloc.

A mocked bloc implements all fields and methods with a default implementation that does not throw a NoSuchMethodError, and may be further customized at runtime to define how it may behave using when and whenListen.

Note: It is critical to explicitly provide the event and state types when extending MockBloc.

GOOD

class MockCounterBloc extends MockBloc<CounterEvent, int>
  implements CounterBloc {}

BAD

class MockCounterBloc extends MockBloc implements CounterBloc {}

Implementation

MockBloc() {
  // ignore: deprecated_member_use
  when(() => mapEventToState(any())).thenAnswer((_) => Stream<S>.empty());
  when(() => add(any())).thenReturn(null);
}