From 146c4fc48abfece19667e3adf0f63ef962bfd932 Mon Sep 17 00:00:00 2001 From: Davide Gallotti Date: Thu, 12 Oct 2023 19:29:44 +0200 Subject: [PATCH] fix(bloc_test): add await before expect --- packages/bloc_test/lib/src/bloc_test.dart | 2 +- packages/bloc_test/test/bloc_bloc_test_test.dart | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/bloc_test/lib/src/bloc_test.dart b/packages/bloc_test/lib/src/bloc_test.dart index 9bca3f6062b..ebeefe5da78 100644 --- a/packages/bloc_test/lib/src/bloc_test.dart +++ b/packages/bloc_test/lib/src/bloc_test.dart @@ -214,7 +214,7 @@ Future testBloc, State>({ await Future.delayed(Duration.zero); await bloc.close(); if (expect != null) { - final dynamic expected = expect(); + final dynamic expected = await expect(); shallowEquality = '$states' == '$expected'; try { test.expect(states, test.wrapMatcher(expected)); diff --git a/packages/bloc_test/test/bloc_bloc_test_test.dart b/packages/bloc_test/test/bloc_bloc_test_test.dart index 0e2c5546ef5..651946e947d 100644 --- a/packages/bloc_test/test/bloc_bloc_test_test.dart +++ b/packages/bloc_test/test/bloc_bloc_test_test.dart @@ -101,6 +101,16 @@ void main() { expect: () => const [11], ); + blocTest( + 'expect is async', + build: () => CounterBloc(), + act: (bloc) => bloc.add(CounterEvent.increment), + expect: () async { + await Future.delayed(Duration.zero); + return const [1]; + }, + ); + test('fails immediately when expectation is incorrect', () async { const expectedError = 'Expected: [2]\n' ' Actual: [1]\n'