Skip to content

Commit

Permalink
feat(FakeAsync): check pending timers at the end of fakeAsync in Dart
Browse files Browse the repository at this point in the history
Made possible with quiver 0.21.4
  • Loading branch information
vicb committed Jun 4, 2015
1 parent 31a3a19 commit 53694eb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion modules/angular2/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
logging: '>=0.9.0 <0.12.0'
source_span: '^1.0.0'
stack_trace: '^1.1.1'
quiver: '^0.21.3+1'
quiver: '^0.21.4'
dev_dependencies:
guinness: '^0.1.17'
transformers:
Expand Down
25 changes: 13 additions & 12 deletions modules/angular2/src/test_lib/fake_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ Function fakeAsync(Function fn) {
return new quiver.FakeAsync().run((quiver.FakeAsync async) {
try {
_fakeAsync = async;
List args = [
a0,
a1,
a2,
a3,
a4,
a5,
a6,
a7,
a8,
a9
].takeWhile((a) => a != _u).toList();
List args = [a0, a1, a2, a3, a4, a5, a6, a7, a8, a9]
.takeWhile((a) => a != _u).toList();
var res = Function.apply(fn, args);
_fakeAsync.flushMicrotasks();

if (async.periodicTimerCount > 0) {
throw new BaseException('${async.periodicTimerCount} periodic '
'timer(s) still in the queue.');
}

if (async.nonPeriodicTimerCount > 0) {
throw new BaseException('${async.nonPeriodicTimerCount} timer(s) '
'still in the queue.');
}

return res;
} finally {
_fakeAsync = null;
Expand Down
4 changes: 0 additions & 4 deletions modules/angular2/test/test_lib/fake_async_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,11 @@ export function main() {
}));

it('should throw an error on dangling timers', () => {
// TODO(vicb): https://github.com/google/quiver-dart/issues/248
if (IS_DARTIUM) return;
expect(() => { fakeAsync(() => { TimerWrapper.setTimeout(() => {}, 10); })(); })
.toThrowError('1 timer(s) still in the queue.');
});

it('should throw an error on dangling periodic timers', () => {
// TODO(vicb): https://github.com/google/quiver-dart/issues/248
if (IS_DARTIUM) return;
expect(() => { fakeAsync(() => { TimerWrapper.setInterval(() => {}, 10); })(); })
.toThrowError('1 periodic timer(s) still in the queue.');
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ environment:
dev_dependencies:
guinness: '^0.1.17'
unittest: '^0.11.5+4'
quiver: '^0.21.3+1'
quiver: '^0.21.4'

0 comments on commit 53694eb

Please sign in to comment.