style(mock): make jslint and igor happier

This commit is contained in:
Vojta Jina 2012-01-11 14:35:02 -08:00
parent 28114de8dc
commit 9a8dbfef51

51
src/angular-mocks.js vendored
View file

@ -33,11 +33,12 @@ angular.mock = {};
* - $browser.defer enables testing of code that uses * - $browser.defer enables testing of code that uses
* {@link angular.module.ng.$defer $defer} for executing functions via the `setTimeout` api. * {@link angular.module.ng.$defer $defer} for executing functions via the `setTimeout` api.
*/ */
angular.mock.$BrowserProvider = function(){ angular.mock.$BrowserProvider = function() {
this.$get = function(){ this.$get = function(){
return new angular.mock.$Browser(); return new angular.mock.$Browser();
}; };
}; };
angular.mock.$Browser = function() { angular.mock.$Browser = function() {
var self = this; var self = this;
@ -143,7 +144,7 @@ angular.mock.$Browser = function() {
self.$$scripts.push(script); self.$$scripts.push(script);
return script; return script;
}; };
} };
angular.mock.$Browser.prototype = { angular.mock.$Browser.prototype = {
/** /**
@ -217,7 +218,7 @@ angular.mock.$Browser.prototype = {
* information. * information.
*/ */
angular.mock.$ExceptionHandlerProvider = function(){ angular.mock.$ExceptionHandlerProvider = function() {
var handler; var handler;
/** /**
@ -238,18 +239,18 @@ angular.mock.$ExceptionHandlerProvider = function(){
* See {@link angular.module.ngMock.$log#assertEmpty assertEmpty()} and * See {@link angular.module.ngMock.$log#assertEmpty assertEmpty()} and
* {@link angular.module.ngMock.$log#reset reset()} * {@link angular.module.ngMock.$log#reset reset()}
*/ */
this.mode = function(mode){ this.mode = function(mode) {
switch(mode) { switch(mode) {
case 'rethrow': case 'rethrow':
handler = function(e) { handler = function(e) {
throw e; throw e;
} };
break; break;
case 'log': case 'log':
var errors = []; var errors = [];
handler = function(e) { handler = function(e) {
errors.push(e); errors.push(e);
} };
handler.errors = errors; handler.errors = errors;
break; break;
default: default:
@ -257,7 +258,7 @@ angular.mock.$ExceptionHandlerProvider = function(){
} }
}; };
this.$get = function(){ this.$get = function() {
return handler; return handler;
}; };
@ -275,7 +276,7 @@ angular.mock.$ExceptionHandlerProvider = function(){
* level-specific log function, e.g. for level `error` the array is exposed as `$log.error.logs`. * level-specific log function, e.g. for level `error` the array is exposed as `$log.error.logs`.
* *
*/ */
angular.mock.$logProvider = function(){ angular.mock.$LogProvider = function() {
function concat(array1, array2, index) { function concat(array1, array2, index) {
return array1.concat(Array.prototype.slice.call(array2, index)); return array1.concat(Array.prototype.slice.call(array2, index));
@ -298,7 +299,7 @@ angular.mock.$logProvider = function(){
* @description * @description
* Reset all of the logging arrays to empty. * Reset all of the logging arrays to empty.
*/ */
$log.reset = function (){ $log.reset = function () {
/** /**
* @ngdoc property * @ngdoc property
* @name angular.module.ngMock.$log#log.logs * @name angular.module.ngMock.$log#log.logs
@ -357,7 +358,7 @@ angular.mock.$logProvider = function(){
if (errors.length) { if (errors.length) {
errors.unshift("Expected $log to be empty! Either a message was logged unexpectedly, or an expected " + errors.unshift("Expected $log to be empty! Either a message was logged unexpectedly, or an expected " +
"log message was not checked and removed:"); "log message was not checked and removed:");
errors.push('') errors.push('');
throw new Error(errors.join('\n---------\n')); throw new Error(errors.join('\n---------\n'));
} }
}; };
@ -504,7 +505,7 @@ angular.mock.TzDate = function (offset, timestamp) {
}); });
return self; return self;
} };
//make "tzDateInstance instanceof Date" return true //make "tzDateInstance instanceof Date" return true
angular.mock.TzDate.prototype = Date.prototype; angular.mock.TzDate.prototype = Date.prototype;
@ -524,7 +525,7 @@ angular.mock.TzDate.prototype = Date.prototype;
* @param {*} object - any object to turn into string. * @param {*} object - any object to turn into string.
* @return a serialized string of the argument * @return a serialized string of the argument
*/ */
angular.mock.dump = function(object){ angular.mock.dump = function(object) {
return serialize(object); return serialize(object);
function serialize(object) { function serialize(object) {
@ -532,8 +533,8 @@ angular.mock.dump = function(object){
if (angular.isElement(object)) { if (angular.isElement(object)) {
object = angular.element(object); object = angular.element(object);
out = angular.element('<div></div>') out = angular.element('<div></div>');
angular.forEach(object, function(element){ angular.forEach(object, function(element) {
out.append(angular.element(element).clone()); out.append(angular.element(element).clone());
}); });
out = out.html(); out = out.html();
@ -616,7 +617,7 @@ function createHttpBackendMock($delegate, $defer) {
return angular.isNumber(status) return angular.isNumber(status)
? [status, data, headers] ? [status, data, headers]
: [200, status, data]; : [200, status, data];
} };
} }
// TODO(vojta): change params to: method, url, data, headers, callback // TODO(vojta): change params to: method, url, data, headers, callback
@ -850,10 +851,10 @@ function MockXhr() {
* mocks to the {@link angular.module.AUTO.$injector $injector}. * mocks to the {@link angular.module.AUTO.$injector $injector}.
*/ */
angular.module('ngMock', ['ng']).service({ angular.module('ngMock', ['ng']).service({
'$browser': angular.mock.$BrowserProvider, $browser: angular.mock.$BrowserProvider,
'$exceptionHandler': angular.mock.$ExceptionHandlerProvider, $exceptionHandler: angular.mock.$ExceptionHandlerProvider,
'$log': angular.mock.$logProvider, $log: angular.mock.$LogProvider,
'$httpBackend': angular.mock.$HttpBackendProvider $httpBackend: angular.mock.$HttpBackendProvider
}); });
@ -875,13 +876,13 @@ angular.mock.e2e.$httpBackendDecorator = ['$delegate', '$defer', createHttpBacke
window.jstestdriver && (function(window){ window.jstestdriver && (function(window) {
/** /**
* Global method to output any number of objects into JSTD console. Useful for debugging. * Global method to output any number of objects into JSTD console. Useful for debugging.
*/ */
window.dump = function() { window.dump = function() {
var args = []; var args = [];
angular.forEach(arguments, function(arg){ angular.forEach(arguments, function(arg) {
args.push(angular.mock.dump(arg)); args.push(angular.mock.dump(arg));
}); });
jstestdriver.console.log.apply(jstestdriver.console, args); jstestdriver.console.log.apply(jstestdriver.console, args);
@ -911,7 +912,7 @@ window.jstestdriver && (function(window){
* }); * });
* *
* // Argument inference is used to inject the $rootScope as well as the version * // Argument inference is used to inject the $rootScope as well as the version
* it('should provide a version', inject(function($rootScope, version){ * it('should provide a version', inject(function($rootScope, version) {
* expect(version).toEqual('v1.0.1'); * expect(version).toEqual('v1.0.1');
* expect($rootScope.value).toEqual(123); * expect($rootScope.value).toEqual(123);
* }); * });
@ -933,10 +934,10 @@ window.jstestdriver && (function(window){
* @param {*} fns... any number of functions which will be injected using the injector. * @param {*} fns... any number of functions which will be injected using the injector.
* @return a method * @return a method
*/ */
window.jasmine && (function(window){ window.jasmine && (function(window) {
window.inject = function (){ window.inject = function () {
var blockFns = Array.prototype.slice.call(arguments, 0); var blockFns = Array.prototype.slice.call(arguments, 0);
return function(){ return function() {
var injector = this.$injector; var injector = this.$injector;
if (!injector) { if (!injector) {
injector = this.$injector = angular.injector('ng', 'ngMock'); injector = this.$injector = angular.injector('ng', 'ngMock');