diff --git a/lib/testing/src/fake_async.dart b/lib/testing/src/fake_async.dart index b2ce951..34b9977 100644 --- a/lib/testing/src/fake_async.dart +++ b/lib/testing/src/fake_async.dart @@ -248,8 +248,8 @@ class _FakeAsync extends FakeAsync { timer._callback(timer); timer._nextCall += timer._duration; } else { - timer._callback(); _timers.remove(timer); + timer._callback(); } } diff --git a/test/testing/fake_async_test.dart b/test/testing/fake_async_test.dart index 7319f43..882a0fc 100644 --- a/test/testing/fake_async_test.dart +++ b/test/testing/fake_async_test.dart @@ -598,5 +598,27 @@ main() { }); }); }); + + group('timers', () { + test('should behave like real timers', () { + return new FakeAsync().run((async) { + var timeout = const Duration(minutes: 1); + int counter = 0; + var timer; + timer = new Timer(timeout, () { + counter++; + expect(timer.isActive, isFalse, + reason: "is not active while executing callback"); + }); + expect(timer.isActive, isTrue, + reason: "is active before executing callback"); + async.elapse(timeout); + expect(counter, equals(1), reason: "timer executed"); + expect(timer.isActive, isFalse, + reason: "is not active after executing callback"); + }); + }); + ; + }); }); }