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

Commit 63cca9a

Browse files
IgorMinarvojtajina
authored andcommitted
feat(browser.defer): flush should throw exception when queue is empty
1 parent d47ec77 commit 63cca9a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/angular-mocks.js

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ angular.module.ngMock.$Browser = function() {
125125
} else {
126126
if (self.deferredFns.length) {
127127
self.defer.now = self.deferredFns[self.deferredFns.length-1].time;
128+
} else {
129+
throw Error('No deferred tasks to be flushed');
128130
}
129131
}
130132

test/angular-mocksSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ describe('mocks', function() {
291291
expect(browser.defer.now).toEqual(3);
292292
expect(log).toEqual('A;B;C;');
293293
});
294+
295+
it('should throw an exception if there is nothing to be flushed', function() {
296+
expect(function() {browser.defer.flush();}).toThrow('No deferred tasks to be flushed');
297+
});
294298
});
295299

296300

test/service/deferSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('$defer', function() {
1717
$browser.defer.flush();
1818
expect(counter).toBe(1);
1919

20-
$browser.defer.flush(); //does nothing
20+
expect(function() {$browser.defer.flush();}).toThrow('No deferred tasks to be flushed');
2121
expect(counter).toBe(1);
2222

2323
expect($exceptionHandler).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)