Skip to content

Commit

Permalink
fix(bloc_test): add await before expect
Browse files Browse the repository at this point in the history
  • Loading branch information
gallottino committed Oct 12, 2023
1 parent dc1958c commit 146c4fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/bloc_test/lib/src/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Future<void> testBloc<B extends BlocBase<State>, State>({
await Future<void>.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));
Expand Down
10 changes: 10 additions & 0 deletions packages/bloc_test/test/bloc_bloc_test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ void main() {
expect: () => const <int>[11],
);

blocTest<CounterBloc, int>(
'expect is async',
build: () => CounterBloc(),
act: (bloc) => bloc.add(CounterEvent.increment),
expect: () async {
await Future<void>.delayed(Duration.zero);
return const <int>[1];
},
);

test('fails immediately when expectation is incorrect', () async {
const expectedError = 'Expected: [2]\n'
' Actual: [1]\n'
Expand Down

0 comments on commit 146c4fc

Please sign in to comment.