You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have stumbled across a difference in behavior between stream.first and stream.firstOrNull when using timeouts with fakeAsync:
// Passes as expectedtest('stream.first with timeout', () async {
fakeAsync((FakeAsyncasync) {
expect(
Stream<int>.value(0).first.timeout(constDuration(seconds:1)),
completion(0),
);
async.elapse(constDuration(seconds:10));
});
});
// Fails with timeout exceptiontest('stream.firstOrNull with timeout', () async {
fakeAsync((FakeAsyncasync) {
expect(
Stream<int>.value(0).firstOrNull.timeout(constDuration(seconds:1)),
completion(0),
);
async.elapse(constDuration(seconds:10));
});
});
I would expect these tests to behave identically given that both streams are guaranteed to have a value. Could this be the intended behavior? My main concern is that fakeAsync is sensitive to the implementation details of methods that otherwise behave identically (in this case because the stream has a value). This would make refactoring tested code a real pain. But maybe I am missing something.
I only ran into this issue while writing tests with fakeAsync. The actual code being tested, which uses firstOrNull, seems to work fine while debugging, but the tests fail because of the timeout.
As a workaround, I am using a custom firstOrNull with a slightly different implementation that makes it work like I would expect:
I have stumbled across a difference in behavior between stream.first and stream.firstOrNull when using timeouts with fakeAsync:
I would expect these tests to behave identically given that both streams are guaranteed to have a value. Could this be the intended behavior? My main concern is that fakeAsync is sensitive to the implementation details of methods that otherwise behave identically (in this case because the stream has a value). This would make refactoring tested code a real pain. But maybe I am missing something.
I only ran into this issue while writing tests with fakeAsync. The actual code being tested, which uses firstOrNull, seems to work fine while debugging, but the tests fail because of the timeout.
As a workaround, I am using a custom firstOrNull with a slightly different implementation that makes it work like I would expect:
(Not sure if this mimics firstOrNull 100%, but dropping it in my code fixed my issues)
My first attempt at an alternate firstOrNull implementation gave me the same problem when applying timeouts in a fakeAsync:
The text was updated successfully, but these errors were encountered: