Merge branch 'master' of github.com:angular/angular.js

This commit is contained in:
Misko Hevery 2010-05-20 16:56:22 -07:00
commit d485421e0e
3 changed files with 43 additions and 7 deletions

View file

@ -64,11 +64,16 @@ angularService("$location", function(browser){
return location; return location;
}, {inject: ['$browser']}); }, {inject: ['$browser']});
angularService("$log", function(){ angularService("$log", function($window){
var console = $window.console,
log = console && console.log || noop;
return { 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) { angularService("$hover", function(browser) {
var tooltip, self = this, error, width = 300, arrowWidth = 10; var tooltip, self = this, error, width = 300, arrowWidth = 10;
@ -229,7 +234,7 @@ angularService('$xhr', function($browser, $error, $log){
angularService('$xhr.error', function($log){ angularService('$xhr.error', function($log){
return function(request, response){ return function(request, response){
$log.error(response); $log.error('ERROR: XHR: ' + request.url, request, response);
}; };
}, {inject:['$log']}); }, {inject:['$log']});
@ -267,7 +272,7 @@ angularService('$xhr.bulk', function($xhr, $error, $log){
if (response.status == 200) { if (response.status == 200) {
(currentRequests[i].callback || noop)(response.status, response.response); (currentRequests[i].callback || noop)(response.status, response.response);
} else { } else {
$error(currentRequests[i], {status: response.status, body:response.response}); $error(currentRequests[i], response);
} }
} catch(e) { } catch(e) {
$log.error(e); $log.error(e);

View file

@ -54,7 +54,7 @@ function MockBrowser() {
var expect = expectations[method] || (expectations[method] = {}); var expect = expectations[method] || (expectations[method] = {});
return { return {
respond: function(code, response) { respond: function(code, response) {
if (!isNumber(code)) { if (!angular.isNumber(code)) {
response = code; response = code;
code = 200; code = 200;
} }

View file

@ -31,6 +31,37 @@ describe("service", function(){
scope.$document.addStyleSheet('css/angular.css'); 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(){ describe("$location", function(){
it("should inject $location", function(){ it("should inject $location", function(){
scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value'); scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value');
@ -257,7 +288,7 @@ describe("service", function(){
expect(typeof cb).toEqual('function'); expect(typeof cb).toEqual('function');
expect($xhrError).wasCalledWith( expect($xhrError).wasCalledWith(
{url:'/req1', method:'GET', data:null, callback:cb}, {url:'/req1', method:'GET', data:null, callback:cb},
{status:404, body:'NotFound'}); {status:404, response:'NotFound'});
expect(log).toEqual('"second";DONE'); expect(log).toEqual('"second";DONE');
}); });