mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
added $log to console connection
This commit is contained in:
parent
31b35b141f
commit
80e12276f4
2 changed files with 39 additions and 3 deletions
|
|
@ -64,11 +64,16 @@ angularService("$location", function(browser){
|
|||
return location;
|
||||
}, {inject: ['$browser']});
|
||||
|
||||
angularService("$log", function(){
|
||||
angularService("$log", function($window){
|
||||
var console = $window.console,
|
||||
log = console && console.log || noop;
|
||||
return {
|
||||
error: noop
|
||||
log: log,
|
||||
warn: console && console.warn || log,
|
||||
info: console && console.info || log,
|
||||
error: console && console.error || log
|
||||
};
|
||||
});
|
||||
}, {inject:['$window']});
|
||||
|
||||
angularService("$hover", function(browser) {
|
||||
var tooltip, self = this, error, width = 300, arrowWidth = 10;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,37 @@ describe("service", function(){
|
|||
scope.$document.addStyleSheet('css/angular.css');
|
||||
});
|
||||
|
||||
describe("$log", function(){
|
||||
it('should use console if present', function(){
|
||||
function log(){};
|
||||
function warn(){};
|
||||
function info(){};
|
||||
function error(){};
|
||||
var scope = createScope(null, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}});
|
||||
expect(scope.$log.log).toEqual(log);
|
||||
expect(scope.$log.warn).toEqual(warn);
|
||||
expect(scope.$log.info).toEqual(info);
|
||||
expect(scope.$log.error).toEqual(error);
|
||||
});
|
||||
|
||||
it('should use console.log if other not present', function(){
|
||||
function log(){};
|
||||
var scope = createScope(null, angularService, {$window: {console:{log:log}}});
|
||||
expect(scope.$log.log).toEqual(log);
|
||||
expect(scope.$log.warn).toEqual(log);
|
||||
expect(scope.$log.info).toEqual(log);
|
||||
expect(scope.$log.error).toEqual(log);
|
||||
});
|
||||
|
||||
it('should use noop if no console', function(){
|
||||
var scope = createScope(null, angularService, {$window: {}});
|
||||
expect(scope.$log.log).toEqual(noop);
|
||||
expect(scope.$log.warn).toEqual(noop);
|
||||
expect(scope.$log.info).toEqual(noop);
|
||||
expect(scope.$log.error).toEqual(noop);
|
||||
});
|
||||
});
|
||||
|
||||
describe("$location", function(){
|
||||
it("should inject $location", function(){
|
||||
scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value');
|
||||
|
|
|
|||
Loading…
Reference in a new issue