feat(FakeAsync): check pending timers at the end of fakeAsync in Dart
Made possible with quiver 0.21.4
This commit is contained in:
parent
31a3a19dac
commit
53694eb64a
|
@ -17,7 +17,7 @@ dependencies:
|
||||||
logging: '>=0.9.0 <0.12.0'
|
logging: '>=0.9.0 <0.12.0'
|
||||||
source_span: '^1.0.0'
|
source_span: '^1.0.0'
|
||||||
stack_trace: '^1.1.1'
|
stack_trace: '^1.1.1'
|
||||||
quiver: '^0.21.3+1'
|
quiver: '^0.21.4'
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
guinness: '^0.1.17'
|
guinness: '^0.1.17'
|
||||||
transformers:
|
transformers:
|
||||||
|
|
|
@ -30,20 +30,21 @@ Function fakeAsync(Function fn) {
|
||||||
return new quiver.FakeAsync().run((quiver.FakeAsync async) {
|
return new quiver.FakeAsync().run((quiver.FakeAsync async) {
|
||||||
try {
|
try {
|
||||||
_fakeAsync = async;
|
_fakeAsync = async;
|
||||||
List args = [
|
List args = [a0, a1, a2, a3, a4, a5, a6, a7, a8, a9]
|
||||||
a0,
|
.takeWhile((a) => a != _u).toList();
|
||||||
a1,
|
|
||||||
a2,
|
|
||||||
a3,
|
|
||||||
a4,
|
|
||||||
a5,
|
|
||||||
a6,
|
|
||||||
a7,
|
|
||||||
a8,
|
|
||||||
a9
|
|
||||||
].takeWhile((a) => a != _u).toList();
|
|
||||||
var res = Function.apply(fn, args);
|
var res = Function.apply(fn, args);
|
||||||
_fakeAsync.flushMicrotasks();
|
_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;
|
return res;
|
||||||
} finally {
|
} finally {
|
||||||
_fakeAsync = null;
|
_fakeAsync = null;
|
||||||
|
|
|
@ -158,15 +158,11 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should throw an error on dangling timers', () => {
|
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); })(); })
|
expect(() => { fakeAsync(() => { TimerWrapper.setTimeout(() => {}, 10); })(); })
|
||||||
.toThrowError('1 timer(s) still in the queue.');
|
.toThrowError('1 timer(s) still in the queue.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error on dangling periodic timers', () => {
|
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); })(); })
|
expect(() => { fakeAsync(() => { TimerWrapper.setInterval(() => {}, 10); })(); })
|
||||||
.toThrowError('1 periodic timer(s) still in the queue.');
|
.toThrowError('1 periodic timer(s) still in the queue.');
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,4 +4,4 @@ environment:
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
guinness: '^0.1.17'
|
guinness: '^0.1.17'
|
||||||
unittest: '^0.11.5+4'
|
unittest: '^0.11.5+4'
|
||||||
quiver: '^0.21.3+1'
|
quiver: '^0.21.4'
|
||||||
|
|
Loading…
Reference in New Issue