From f0c6ebc07653f6267acec898ccef5677884e3081 Mon Sep 17 00:00:00 2001 From: petrovalex Date: Sat, 15 Sep 2012 19:02:10 +0300 Subject: feat($timeout-mock): add verifyNoPendingTasks method added verifyNoPendingTasks method, which throws error if not all deferred tasks have been flushed Closes #1245 --- test/ngMock/angular-mocksSpec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 5992846d..d95f3003 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -327,6 +327,22 @@ describe('ngMock', function() { $timeout.flush(); expect(logger).toEqual(['t1', 't3', 't2']); })); + + + it('should throw an exception when not flushed', inject(function($timeout){ + $timeout(noop); + + var expectedError = 'Deferred tasks to flush (1): {id: 0, time: 0}'; + expect(function() {$timeout.verifyNoPendingTasks();}).toThrow(expectedError); + })); + + + it('should do nothing when all tasks have been flushed', inject(function($timeout) { + $timeout(noop); + + $timeout.flush(); + expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow(); + })); }); -- cgit v1.2.3