This is a very simplified version of the problem I have encountered when trying to unit tests streams.
The test checks that the correct event has been added to the stream - it appears to work fine - for example, change the value add( 'test')
to add( 'test2')
will fail the test.
But when you comment out the line fireKeepAliveMessage(message);
so that the event does not throw, the unit test will simply run forever.
How can I add some sort of timeout to the test? Or is there a better approach to this problem?
library stream_test;
import "package:unittest/unittest.dart";
import "dart:async";
void main() {
test("aa", () {
StreamController streamController = new StreamController();
streamController.add( "test");
Stream underTest = streamController.stream;
underTest.first.then(expectAsync((e){
expect( e, equals( "test"));
}));
});
}
I would do it like: