mogen_unit_tests 1.4.2
mogen_unit_tests: ^1.4.2 copied to clipboard
Scans Riverpod notifiers and flutter_bloc blocs/cubits, then auto-generates Mocktail and bloc_test unit tests.
1.4.2 #
- The initial-state test asserts the class named in
super(...)(super(SearchInitial())→isA<SearchInitial>()) instead of the base state type, which was trivially true.
1.4.1 #
Fixed #
- flutter_bloc support.
Bloc<Event, State>andCubit<State>classes are now detected alongside Riverpod notifiers, and get tests built on thebloc_testpackage (blocTest<B, S>(...)withbuild:,act:,setUp:,verify:anderrors:). - Both bloc state shapes are asserted, instead of one excluding the other: a
state expressed as subtypes (
class FeatureSuccess extends FeatureState) is asserted by type, a state expressed as fields (isLoading/error/success) field by field, and a state that does both gets both assertions. - Fields are no longer read off
bloc.statewhen the matched state class isn't the bloc's declared state type — the name-prefix fallback can match a subclass, whose fields the base type doesn't declare and wouldn't compile.
1.4.0 #
Added #
- A bloc is driven by its events: every
on<Event>(...)registration becomes a test group whoseact:adds a real event instance, built from the event class's own constructor. Both inline(event, emit) {...}closures and tear-off handlers are supported. - A cubit is driven by its public methods.
- Constructor-injected collaborators are mocked and passed into
build:. - A bloc/cubit dependency is mocked with
bloc_test'sMockBloc/MockCubitand has itsstatestubbed, since a bareMockhas no state stream. - Calls made by the constructor itself are stubbed once in
setUp()and never failed in the error path —build:runs after ablocTest'ssetUp:, so failing them would break construction instead of the action. - State assertions are read off the handler's own
emit(...)calls: a state class with the conventional fields is asserted field by field, and a sealed state hierarchy — whose base class has no fields — is asserted by type (emit(SearchSuccess(...))becomesexpect(bloc.state, isA<SearchSuccess>()), and the emit inside thecatchbecomes the error test's assertion). - The real emitted sequence is offered as a ready-to-uncomment
// expect: () => [isA<SearchLoading>(), isA<SearchSuccess>()],. It stays commented because a guarded or looped emit doesn't run as many times as it appears in source. - When a handler doesn't catch the failure, the error test asserts
errors: () => [isA<AppException>()]instead of a state field the error never reaches. - The feature scan now covers
presentation/bloc,presentation/blocs,presentation/cubit,presentation/cubits,presentation/logicand top-levelbloc/,cubit/folders in addition topresentation/notifiers. - State and event classes declared as
partof a bloc file are recognised as such and are no longer imported separately (importing a part file does not compile).
Fixed #
required this.xconstructor parameters resolved to the literal typethis.instead of the field's declared type, which leaked into generated imports and values.- A method-scoped call scan also picked up calls made in the class's constructor.