diff options
| author | Vojta Jina | 2011-02-04 01:32:55 +0000 |
|---|---|---|
| committer | Igor Minar | 2011-02-04 14:18:28 -0800 |
| commit | 9798f5e35fd150c319004c953ed627b5b28dad71 (patch) | |
| tree | 7e7a4935910710a619d4bd0f64338a0e85a09403 | |
| parent | 94bf24e3b65ba0e3a8a59b35e6c2b24e298c26d3 (diff) | |
| download | angular.js-9798f5e35fd150c319004c953ed627b5b28dad71.tar.bz2 | |
mock $log: fixed bug, added some tests
I extracted mock $log factory into stand alone function, so we can access it and test, because this service is rewritten by real service during testing, so we can't access it through angular.$service('$log')...
| -rw-r--r-- | src/angular-mocks.js | 14 | ||||
| -rw-r--r-- | test/angular-mocksSpec.js | 43 |
2 files changed, 51 insertions, 6 deletions
diff --git a/src/angular-mocks.js b/src/angular-mocks.js index bbdcc94d..38163646 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -241,12 +241,14 @@ angular.service('$exceptionHandler', function(e) { * * See {@link angular.mock} for more info on angular mocks. */ -angular.service('$log', function() { +angular.service('$log', MockLogFactory); + +function MockLogFactory() { var $log = { - log: function(){ $log.logs.push(arguments); }, - warn: function(){ $log.logs.push(arguments); }, - info: function(){ $log.logs.push(arguments); }, - error: function(){ $log.logs.push(arguments); } + log: function(){ $log.log.logs.push(arguments); }, + warn: function(){ $log.warn.logs.push(arguments); }, + info: function(){ $log.info.logs.push(arguments); }, + error: function(){ $log.error.logs.push(arguments); } }; $log.log.logs = []; @@ -255,7 +257,7 @@ angular.service('$log', function() { $log.error.logs = []; return $log; -}); +} /** diff --git a/test/angular-mocksSpec.js b/test/angular-mocksSpec.js index b96a9cfc..fabc47ea 100644 --- a/test/angular-mocksSpec.js +++ b/test/angular-mocksSpec.js @@ -119,3 +119,46 @@ describe('TzDate', function() { expect(date2.getUTCSeconds()).toBe(0); }); }); + +describe('$log', function() { + var $log; + beforeEach(function() { + $log = MockLogFactory(); + }); + + it('should provide log method', function() { + expect(function() { $log.log(''); }).not.toThrow(); + }); + + it('should provide info method', function() { + expect(function() { $log.info(''); }).not.toThrow(); + }); + + it('should provide warn method', function() { + expect(function() { $log.warn(''); }).not.toThrow(); + }); + + it('should provide error method', function() { + expect(function() { $log.error(''); }).not.toThrow(); + }); + + it('should store log messages', function() { + $log.log('fake log'); + expect($log.log.logs).toContain(['fake log']); + }); + + it('should store info messages', function() { + $log.info('fake log'); + expect($log.info.logs).toContain(['fake log']); + }); + + it('should store warn messages', function() { + $log.warn('fake log'); + expect($log.warn.logs).toContain(['fake log']); + }); + + it('should store error messages', function() { + $log.error('fake log'); + expect($log.error.logs).toContain(['fake log']); + }); +}); |
