Skip to content

Commit 23c2f1d

Browse files
committed
fix(mocks): $timeout.flushNext should throw an exception
we can't use Jasmine's `expect` here since this code should be library agnostic
1 parent ac8d5da commit 23c2f1d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ngMock/angular-mocks.js

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

134-
if (angular.isDefined(expectedDelay)) {
135-
expect(tick.time).toEqual(expectedDelay);
134+
if (angular.isDefined(expectedDelay) && (tick.time !== expectedDelay)) {
135+
throw new Error("Expected a task to be scheduled with " + expectedDelay + "ms delay, but it was " + tick.time +
136+
"ms.");
136137
}
137138

138139
tick.fn();

test/ngMock/angular-mocksSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ describe('ngMock', function() {
430430
$timeout.flushNext();
431431
$timeout.flushNext();
432432
}));
433+
434+
435+
it("should throw an exception when flushed with flushNext and the expectedDelay doesn't match the actual delay",
436+
inject(function($timeout) {
437+
$timeout(function() {}, 100);
438+
439+
expect(function() {
440+
$timeout.flushNext(4000);
441+
}).toThrow("Expected a task to be scheduled with 4000ms delay, but it was 100ms.");
442+
}));
433443
});
434444

435445

0 commit comments

Comments
 (0)