mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 15:50:22 +00:00
the flag must be in all src and test files so that we get the benefit of running in the strict mode even in jstd the following script was used to modify all files: for file in `find src test -name "*.js"`; do echo -e "'use strict';\n" > temp.txt cat $file >> temp.txt mv temp.txt $file done
102 lines
2.6 KiB
JavaScript
102 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
describe('$log', function() {
|
|
var scope;
|
|
|
|
beforeEach(function(){
|
|
scope = angular.scope();
|
|
});
|
|
|
|
|
|
afterEach(function(){
|
|
dealoc(scope);
|
|
});
|
|
|
|
|
|
it('should use console if present', function(){
|
|
var logger = "";
|
|
function log(){ logger+= 'log;'; }
|
|
function warn(){ logger+= 'warn;'; }
|
|
function info(){ logger+= 'info;'; }
|
|
function error(){ logger+= 'error;'; }
|
|
var scope = createScope({}, {$log: $logFactory},
|
|
{$exceptionHandler: rethrow,
|
|
$window: {console: {log: log,
|
|
warn: warn,
|
|
info: info,
|
|
error: error}}}),
|
|
$log = scope.$service('$log');
|
|
|
|
$log.log();
|
|
$log.warn();
|
|
$log.info();
|
|
$log.error();
|
|
expect(logger).toEqual('log;warn;info;error;');
|
|
});
|
|
|
|
|
|
it('should use console.log() if other not present', function(){
|
|
var logger = "";
|
|
function log(){ logger+= 'log;'; }
|
|
var scope = createScope({}, {$log: $logFactory},
|
|
{$window: {console:{log:log}},
|
|
$exceptionHandler: rethrow});
|
|
var $log = scope.$service('$log');
|
|
$log.log();
|
|
$log.warn();
|
|
$log.info();
|
|
$log.error();
|
|
expect(logger).toEqual('log;log;log;log;');
|
|
});
|
|
|
|
|
|
it('should use noop if no console', function(){
|
|
var scope = createScope({}, {$log: $logFactory},
|
|
{$window: {},
|
|
$exceptionHandler: rethrow}),
|
|
$log = scope.$service('$log');
|
|
$log.log();
|
|
$log.warn();
|
|
$log.info();
|
|
$log.error();
|
|
});
|
|
|
|
|
|
describe('$log.error', function(){
|
|
var e, $log, errorArgs;
|
|
|
|
beforeEach(function(){
|
|
e = new Error('');
|
|
e.message = undefined;
|
|
e.sourceURL = undefined;
|
|
e.line = undefined;
|
|
e.stack = undefined;
|
|
|
|
$log = $logFactory({console:{error:function(){
|
|
errorArgs = arguments;
|
|
}}});
|
|
});
|
|
|
|
|
|
it('should pass error if does not have trace', function(){
|
|
$log.error('abc', e);
|
|
expect(errorArgs).toEqual(['abc', e]);
|
|
});
|
|
|
|
|
|
it('should print stack', function(){
|
|
e.stack = 'stack';
|
|
$log.error('abc', e);
|
|
expect(errorArgs).toEqual(['abc', 'stack']);
|
|
});
|
|
|
|
|
|
it('should print line', function(){
|
|
e.message = 'message';
|
|
e.sourceURL = 'sourceURL';
|
|
e.line = '123';
|
|
$log.error('abc', e);
|
|
expect(errorArgs).toEqual(['abc', 'message\nsourceURL:123']);
|
|
});
|
|
});
|
|
});
|