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

Commit

Permalink
feat(browser.defer): flush should throw exception when queue is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar authored and vojtajina committed Jan 9, 2012
1 parent d47ec77 commit 63cca9a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});


Expand Down
2 changes: 1 addition & 1 deletion test/service/deferSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 63cca9a

Please sign in to comment.