2019-03-29 06:13:14 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2020-03-05 05:42:28 -05:00
|
|
|
import {ConsoleLogger, DEBUG, ERROR, WARN} from '../../src/logging/console_logger';
|
|
|
|
import {LogLevel} from '../../src/logging/logger';
|
2019-03-29 06:13:14 -04:00
|
|
|
|
|
|
|
describe('ConsoleLogger', () => {
|
|
|
|
it('should pass through calls to Console', () => {
|
|
|
|
spyOn(console, 'debug');
|
|
|
|
spyOn(console, 'info');
|
|
|
|
spyOn(console, 'warn');
|
|
|
|
spyOn(console, 'error');
|
|
|
|
const logger = new ConsoleLogger(LogLevel.debug);
|
|
|
|
|
|
|
|
logger.debug('debug', 'test');
|
|
|
|
expect(console.debug).toHaveBeenCalledWith(DEBUG, 'debug', 'test');
|
|
|
|
|
|
|
|
logger.info('info', 'test');
|
|
|
|
expect(console.info).toHaveBeenCalledWith('info', 'test');
|
|
|
|
|
|
|
|
logger.warn('warn', 'test');
|
|
|
|
expect(console.warn).toHaveBeenCalledWith(WARN, 'warn', 'test');
|
|
|
|
|
|
|
|
logger.error('error', 'test');
|
|
|
|
expect(console.error).toHaveBeenCalledWith(ERROR, 'error', 'test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should filter out calls below the given log level', () => {
|
|
|
|
spyOn(console, 'debug');
|
|
|
|
spyOn(console, 'info');
|
|
|
|
spyOn(console, 'warn');
|
|
|
|
spyOn(console, 'error');
|
|
|
|
const logger = new ConsoleLogger(LogLevel.warn);
|
|
|
|
|
|
|
|
logger.debug('debug', 'test');
|
|
|
|
expect(console.debug).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
logger.info('info', 'test');
|
|
|
|
expect(console.info).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
logger.warn('warn', 'test');
|
|
|
|
expect(console.warn).toHaveBeenCalledWith(WARN, 'warn', 'test');
|
|
|
|
|
|
|
|
logger.error('error', 'test');
|
|
|
|
expect(console.error).toHaveBeenCalledWith(ERROR, 'error', 'test');
|
|
|
|
});
|
2020-03-05 05:42:28 -05:00
|
|
|
|
|
|
|
it('should expose the logging level', () => {
|
|
|
|
expect(new ConsoleLogger(LogLevel.debug).level).toEqual(LogLevel.debug);
|
|
|
|
expect(new ConsoleLogger(LogLevel.info).level).toEqual(LogLevel.info);
|
|
|
|
expect(new ConsoleLogger(LogLevel.warn).level).toEqual(LogLevel.warn);
|
|
|
|
expect(new ConsoleLogger(LogLevel.error).level).toEqual(LogLevel.error);
|
|
|
|
});
|
2019-03-29 06:13:14 -04:00
|
|
|
});
|