From f274c0a66b28711d3b9cc7b0775e97755dd971e8 Mon Sep 17 00:00:00 2001 From: Chirayu Krishnappa Date: Wed, 31 Jul 2013 11:53:02 -0700 Subject: fix(mock.$log): keep in sync with $log Closes #2343 --- test/ngMock/angular-mocksSpec.js | 164 ++++++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 61 deletions(-) (limited to 'test/ngMock/angular-mocksSpec.js') diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 4d238891..9002d854 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -158,83 +158,125 @@ describe('ngMock', function() { describe('$log', function() { - var $log; - beforeEach(inject(['$log', function(log) { - $log = log; - }])); + forEach([true, false], function(debugEnabled) { + describe('debug ' + debugEnabled, function() { + beforeEach(module(function($logProvider) { + $logProvider.debugEnabled(debugEnabled); + })); - afterEach(inject(function($log){ - $log.reset(); - })); + afterEach(inject(function($log){ + $log.reset(); + })); - it('should provide log method', function() { - expect(function() { $log.log(''); }).not.toThrow(); + it("should skip debugging output if disabled", inject(function($log) { + $log.log('fake log'); + $log.info('fake log'); + $log.warn('fake log'); + $log.error('fake log'); + $log.debug('fake log'); + expect($log.log.logs).toContain(['fake log']); + expect($log.info.logs).toContain(['fake log']); + expect($log.warn.logs).toContain(['fake log']); + expect($log.error.logs).toContain(['fake log']); + if (debugEnabled) { + expect($log.debug.logs).toContain(['fake log']); + } else { + expect($log.debug.logs).toEqual([]); + } + })); + }); }); - it('should provide info method', function() { - expect(function() { $log.info(''); }).not.toThrow(); - }); + describe('debug enabled (default)', function() { + var $log; + beforeEach(inject(['$log', function(log) { + $log = log; + }])); - it('should provide warn method', function() { - expect(function() { $log.warn(''); }).not.toThrow(); - }); + afterEach(inject(function($log){ + $log.reset(); + })); - it('should provide error method', function() { - expect(function() { $log.error(''); }).not.toThrow(); - }); + it('should provide the debug method', function() { + expect(function() { $log.log(''); }).not.toThrow(); + }); - it('should store log messages', function() { - $log.log('fake log'); - expect($log.log.logs).toContain(['fake log']); - }); + it('should provide the debug method', function() { + expect(function() { $log.info(''); }).not.toThrow(); + }); - it('should store info messages', function() { - $log.info('fake log'); - expect($log.info.logs).toContain(['fake log']); - }); + it('should provide the debug method', function() { + expect(function() { $log.warn(''); }).not.toThrow(); + }); - it('should store warn messages', function() { - $log.warn('fake log'); - expect($log.warn.logs).toContain(['fake log']); - }); + it('should provide the debug method', function() { + expect(function() { $log.error(''); }).not.toThrow(); + }); - it('should store error messages', function() { - $log.error('fake log'); - expect($log.error.logs).toContain(['fake log']); - }); + it('should provide the debug method', function() { + expect(function() { $log.debug(''); }).not.toThrow(); + }); - it('should assertEmpty', function(){ - try { + 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']); + }); + + it('should store debug messages', function() { + $log.debug('fake log'); + expect($log.debug.logs).toContain(['fake log']); + }); + + it('should assertEmpty', function(){ + try { + $log.error(Error('MyError')); + $log.warn(Error('MyWarn')); + $log.info(Error('MyInfo')); + $log.log(Error('MyLog')); + $log.debug(Error('MyDebug')); + $log.assertEmpty(); + } catch (error) { + error = error.message || error; + expect(error).toMatch(/Error: MyError/m); + expect(error).toMatch(/Error: MyWarn/m); + expect(error).toMatch(/Error: MyInfo/m); + expect(error).toMatch(/Error: MyLog/m); + expect(error).toMatch(/Error: MyDebug/m); + } finally { + $log.reset(); + } + }); + + it('should reset state', function(){ $log.error(Error('MyError')); $log.warn(Error('MyWarn')); $log.info(Error('MyInfo')); $log.log(Error('MyLog')); - $log.assertEmpty(); - } catch (error) { - error = error.message || error; - expect(error).toMatch(/Error: MyError/m); - expect(error).toMatch(/Error: MyWarn/m); - expect(error).toMatch(/Error: MyInfo/m); - expect(error).toMatch(/Error: MyLog/m); - } finally { $log.reset(); - } - }); - - it('should reset state', function(){ - $log.error(Error('MyError')); - $log.warn(Error('MyWarn')); - $log.info(Error('MyInfo')); - $log.log(Error('MyLog')); - $log.reset(); - var passed = false; - try { - $log.assertEmpty(); // should not throw error! - passed = true; - } catch (e) { - passed = e; - } - expect(passed).toBe(true); + var passed = false; + try { + $log.assertEmpty(); // should not throw error! + passed = true; + } catch (e) { + passed = e; + } + expect(passed).toBe(true); + }); }); }); -- cgit v1.2.3