mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 15:50:22 +00:00
- Speed improvements (about 4x on flush phase) - Memory improvements (uses no function closures) - Break $eval into $apply, $dispatch, $flush - Introduced $watch and $observe Breaks angular.equals() use === instead of == Breaks angular.scope() does not take parent as first argument Breaks scope.$watch() takes scope as first argument Breaks scope.$set(), scope.$get are removed Breaks scope.$config is removed Breaks $route.onChange callback has not "this" bounded
102 lines
2.5 KiB
JavaScript
102 lines
2.5 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']);
|
|
});
|
|
});
|
|
});
|