Skip to content

Commit 4ed260b

Browse files
committed
fix(mocks): $timeout.flushNext should throw if nothing to flush
1 parent 23c2f1d commit 4ed260b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/ngMock/angular-mocks.js

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ angular.mock.$Browser = function() {
131131
self.defer.flushNext = function(expectedDelay) {
132132
var tick = self.deferredFns.shift();
133133

134+
if (!tick) {
135+
throw new Error("Nothing to be flushed!");
136+
}
137+
134138
if (angular.isDefined(expectedDelay) && (tick.time !== expectedDelay)) {
135139
throw new Error("Expected a task to be scheduled with " + expectedDelay + "ms delay, but it was " + tick.time +
136140
"ms.");

test/ngMock/angular-mocksSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,13 @@ describe('ngMock', function() {
440440
$timeout.flushNext(4000);
441441
}).toThrow("Expected a task to be scheduled with 4000ms delay, but it was 100ms.");
442442
}));
443+
444+
445+
it("should throw an exception when no task was scheduled but flushNext() was called", inject(function($timeout) {
446+
expect(function() {
447+
$timeout.flushNext();
448+
}).toThrow("Nothing to be flushed!");
449+
}));
443450
});
444451

445452

0 commit comments

Comments
 (0)