diff options
| author | Chirayu Krishnappa | 2013-07-31 11:53:02 -0700 | 
|---|---|---|
| committer | Chirayu Krishnappa | 2013-07-31 13:38:24 -0700 | 
| commit | f274c0a66b28711d3b9cc7b0775e97755dd971e8 (patch) | |
| tree | 8959b8143f4158d46e3f921955da918269752fed /test | |
| parent | 664526d69c927370c93a06745ca38de7cd03a7be (diff) | |
| download | angular.js-f274c0a66b28711d3b9cc7b0775e97755dd971e8.tar.bz2 | |
fix(mock.$log): keep in sync with $log
Closes #2343
Diffstat (limited to 'test')
| -rw-r--r-- | test/ngMock/angular-mocksSpec.js | 164 | 
1 files changed, 103 insertions, 61 deletions
| 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); +      });      });    }); | 
