feat(browser.defer): flush should throw exception when queue is empty

This commit is contained in:
Igor Minar 2011-12-27 15:52:57 -08:00 committed by Vojta Jina
parent d47ec772c3
commit 63cca9afbc
3 changed files with 7 additions and 1 deletions

View file

@ -125,6 +125,8 @@ angular.module.ngMock.$Browser = function() {
} else {
if (self.deferredFns.length) {
self.defer.now = self.deferredFns[self.deferredFns.length-1].time;
} else {
throw Error('No deferred tasks to be flushed');
}
}

View file

@ -291,6 +291,10 @@ describe('mocks', function() {
expect(browser.defer.now).toEqual(3);
expect(log).toEqual('A;B;C;');
});
it('should throw an exception if there is nothing to be flushed', function() {
expect(function() {browser.defer.flush();}).toThrow('No deferred tasks to be flushed');
});
});

View file

@ -17,7 +17,7 @@ describe('$defer', function() {
$browser.defer.flush();
expect(counter).toBe(1);
$browser.defer.flush(); //does nothing
expect(function() {$browser.defer.flush();}).toThrow('No deferred tasks to be flushed');
expect(counter).toBe(1);
expect($exceptionHandler).not.toHaveBeenCalled();