Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/mock/zone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ microLeap() {
*/
isAsyncQueueEmpty() => _asyncQueue.isEmpty;

/**
* Returns whether there are outstanding timers.
*/
isTimerQueueEmpty() => _timerQueue.isEmpty;

/**
* Returns whether there are outstanding non-periodic timers.
*/
isNonPeriodicTimerQueueEmpty() => _timerQueue
.where((_TimerSpec spec) => !spec.periodic)
.isEmpty;

/**
* Returns whether there are outstanding periodic timers.
*/
isPeriodicTimerQueueEmpty() => _timerQueue
.where((_TimerSpec spec) => spec.periodic)
.isEmpty;

/**
* Simulates a clock tick by running any scheduled timers. Can only be used
* in [async] tests.Clock tick will call [microLeap] to process the microtask
Expand Down
22 changes: 22 additions & 0 deletions test/mock/zone_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,28 @@ void main() {
(_) => dump("i never run"));
})).toThrow('1 active timer(s) are still in the queue.');
});

it('should report no timers when there are none', async(() {
expect(isTimerQueueEmpty()).toBe(true);
expect(isNonPeriodicTimerQueueEmpty()).toBe(true);
expect(isPeriodicTimerQueueEmpty()).toBe(true);
}));

it('should report remaining non-periodic timers', async(() {
new Future(() => null);
expect(isTimerQueueEmpty()).toBe(false);
expect(isNonPeriodicTimerQueueEmpty()).toBe(false);
expect(isPeriodicTimerQueueEmpty()).toBe(true);
clockTick();
}));

it('should report remaining periodic timers', async(() {
var t = new Timer.periodic(new Duration(seconds: 1), (_) => null);
expect(isTimerQueueEmpty()).toBe(false);
expect(isNonPeriodicTimerQueueEmpty()).toBe(true);
expect(isPeriodicTimerQueueEmpty()).toBe(false);
t.cancel();
}));
});
});
});
Expand Down