Skip to content

Commit

Permalink
Fix action cubit close status (#89)
Browse files Browse the repository at this point in the history
* test: new isClosed logic

* fix: async import
  • Loading branch information
tomkad99 authored Jan 24, 2025
1 parent 8e11780 commit da103b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/mixins/bloc_action_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ mixin BlocActionMixin<ACTION, S> on BlocBase<S> {
previousAction = action;
}

@override
bool get isClosed => super.isClosed || _streamController.isClosed;

@override
Future<void> close() async {
previousAction = null;
Expand Down
25 changes: 25 additions & 0 deletions test/mixins/bloc_action_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,29 @@ void main() {
expect(true, cubit.actionStreamController.isClosed);
expect(true, cubit.isClosed);
});

testWidgets('should be closed when either state or action stream is closed',
(tester) async {
final cubit = TestCubitWithMixin();
when(() => injector.get<TestCubitWithMixin>()).thenReturn(cubit);

Future<void> build() async {
await tester.pumpWidget(
HookedBlocConfigProvider(
injector: () => injector.get,
child: HookBuilder(
builder: (context) {
useBloc<TestCubitWithMixin>();

return const SizedBox();
},
),
),
);
}

await build();
await cubit.actionStreamController.close();
expect(true, cubit.isClosed);
});
}

0 comments on commit da103b0

Please sign in to comment.