Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 510afbc

Browse files
committed
Revert "fix(ngMock/$interval): add support for zero-delay intervals in tests"
This reverts commit 32f4645.
1 parent 420ceb6 commit 510afbc

File tree

2 files changed

+2
-77
lines changed

2 files changed

+2
-77
lines changed

src/ngMock/angular-mocks.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ angular.mock.$IntervalProvider = function() {
504504
}
505505

506506
repeatFns.push({
507-
nextTime: (now + (delay || 0)),
508-
delay: delay || 1,
507+
nextTime:(now + delay),
508+
delay: delay,
509509
fn: tick,
510510
id: nextRepeatId,
511511
deferred: deferred
@@ -555,16 +555,10 @@ angular.mock.$IntervalProvider = function() {
555555
* @return {number} The amount of time moved forward.
556556
*/
557557
$interval.flush = function(millis) {
558-
var before = now;
559558
now += millis;
560559
while (repeatFns.length && repeatFns[0].nextTime <= now) {
561560
var task = repeatFns[0];
562561
task.fn();
563-
if (task.nextTime === before) {
564-
// this can only happen the first time
565-
// a zero-delay interval gets triggered
566-
task.nextTime++;
567-
}
568562
task.nextTime += task.delay;
569563
repeatFns.sort(function(a, b) { return a.nextTime - b.nextTime;});
570564
}

test/ngMock/angular-mocksSpec.js

-69
Original file line numberDiff line numberDiff line change
@@ -351,75 +351,6 @@ describe('ngMock', function() {
351351
}));
352352

353353

354-
it('should allow you to NOT specify the delay time', inject(function($interval) {
355-
var counterA = 0;
356-
var counterB = 0;
357-
358-
$interval(function() { counterA++; });
359-
$interval(function() { counterB++; }, 0);
360-
361-
$interval.flush(1000);
362-
expect(counterA).toBe(1000);
363-
expect(counterB).toBe(1000);
364-
$interval.flush(1000);
365-
expect(counterA).toBe(2000);
366-
expect(counterB).toBe(2000);
367-
}));
368-
369-
370-
it('should run tasks in correct relative order', inject(function($interval) {
371-
var counterA = 0;
372-
var counterB = 0;
373-
$interval(function() { counterA++; }, 0);
374-
$interval(function() { counterB++; }, 1000);
375-
376-
$interval.flush(1000);
377-
expect(counterA).toBe(1000);
378-
expect(counterB).toBe(1);
379-
$interval.flush(999);
380-
expect(counterA).toBe(1999);
381-
expect(counterB).toBe(1);
382-
$interval.flush(1);
383-
expect(counterA).toBe(2000);
384-
expect(counterB).toBe(2);
385-
}));
386-
387-
388-
it('should NOT trigger zero-delay interval when flush has ran before', inject(function($interval) {
389-
var counterA = 0;
390-
var counterB = 0;
391-
392-
$interval.flush(100);
393-
394-
$interval(function() { counterA++; });
395-
$interval(function() { counterB++; }, 0);
396-
397-
expect(counterA).toBe(0);
398-
expect(counterB).toBe(0);
399-
400-
$interval.flush(100);
401-
402-
expect(counterA).toBe(100);
403-
expect(counterB).toBe(100);
404-
}));
405-
406-
407-
it('should trigger zero-delay interval only once on flush zero', inject(function($interval) {
408-
var counterA = 0;
409-
var counterB = 0;
410-
411-
$interval(function() { counterA++; });
412-
$interval(function() { counterB++; }, 0);
413-
414-
$interval.flush(0);
415-
expect(counterA).toBe(1);
416-
expect(counterB).toBe(1);
417-
$interval.flush(0);
418-
expect(counterA).toBe(1);
419-
expect(counterB).toBe(1);
420-
}));
421-
422-
423354
it('should allow you to specify a number of iterations', inject(function($interval) {
424355
var counter = 0;
425356
$interval(function() {counter++;}, 1000, 2);

0 commit comments

Comments
 (0)