Is there any convenient way to assert all the items emitted by a Stream
in order until it is canceled?
If I use:
expectLater(
stream,
emitsInOrder(<String>[
'item1',
'item2',
]),
);
and the Stream
emits ['item1', 'item2', 'item3']
, the test won't fail.
The only way I've found so far is the following:
var count = 0;
final expected = ['item1', 'item2', 'item3'];
stream.listen(
expectAsync1(
(final result) {
expect(result, expected[count++]);
},
count: expected.length,
),
);
But it is a bit verbose and not very easy to read. Is there a simpler/more elegant way?
emitsDone
can be used if theStream
is closed at some point.E.g:
The test fails with error:
As @Irn suggest, a more compact alternative for
Stream
s that complete at some point is usingtoList
:If the
Stream
is never closed, you can add a timeout and check the items that have been emitted in that period: