summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-mocks/angular-mocks.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/angular-mocks/angular-mocks.js')
-rw-r--r--[-rwxr-xr-x]js/vendor/angular-mocks/angular-mocks.js1187
1 files changed, 771 insertions, 416 deletions
diff --git a/js/vendor/angular-mocks/angular-mocks.js b/js/vendor/angular-mocks/angular-mocks.js
index 2626caab4..efd029bfd 100755..100644
--- a/js/vendor/angular-mocks/angular-mocks.js
+++ b/js/vendor/angular-mocks/angular-mocks.js
@@ -1,13 +1,14 @@
/**
- * @license AngularJS v1.0.8
- * (c) 2010-2012 Google, Inc. http://angularjs.org
+ * @license AngularJS v1.2.14
+ * (c) 2010-2014 Google, Inc. http://angularjs.org
* License: MIT
- *
- * TODO(vojta): wrap whole file into closure during build
*/
+(function(window, angular, undefined) {
+
+'use strict';
/**
- * @ngdoc overview
+ * @ngdoc object
* @name angular.mock
* @description
*
@@ -18,7 +19,7 @@ angular.mock = {};
/**
* ! This is a private undocumented service !
*
- * @name ngMock.$browser
+ * @name $browser
*
* @description
* This service is a mock implementation of {@link ng.$browser}. It provides fake
@@ -75,6 +76,12 @@ angular.mock.$Browser = function() {
};
+ /**
+ * @name $browser#defer.now
+ *
+ * @description
+ * Current milliseconds mock time.
+ */
self.defer.now = 0;
@@ -95,8 +102,7 @@ angular.mock.$Browser = function() {
/**
- * @name ngMock.$browser#defer.flush
- * @methodOf ngMock.$browser
+ * @name $browser#defer.flush
*
* @description
* Flushes all pending requests and executes the defer callbacks.
@@ -110,7 +116,7 @@ angular.mock.$Browser = function() {
if (self.deferredFns.length) {
self.defer.now = self.deferredFns[self.deferredFns.length-1].time;
} else {
- throw Error('No deferred tasks to be flushed');
+ throw new Error('No deferred tasks to be flushed');
}
}
@@ -118,13 +124,6 @@ angular.mock.$Browser = function() {
self.deferredFns.shift().fn();
}
};
- /**
- * @name ngMock.$browser#defer.now
- * @propertyOf ngMock.$browser
- *
- * @description
- * Current milliseconds mock time.
- */
self.$$baseHref = '';
self.baseHref = function() {
@@ -134,8 +133,7 @@ angular.mock.$Browser = function() {
angular.mock.$Browser.prototype = {
/**
- * @name ngMock.$browser#poll
- * @methodOf ngMock.$browser
+ * @name $browser#poll
*
* @description
* run all fns in pollFns
@@ -162,7 +160,7 @@ angular.mock.$Browser.prototype = {
cookies: function(name, value) {
if (name) {
- if (value == undefined) {
+ if (angular.isUndefined(value)) {
delete this.cookieHash[name];
} else {
if (angular.isString(value) && //strings only
@@ -186,17 +184,17 @@ angular.mock.$Browser.prototype = {
/**
- * @ngdoc object
- * @name ngMock.$exceptionHandlerProvider
+ * @ngdoc provider
+ * @name $exceptionHandlerProvider
*
* @description
- * Configures the mock implementation of {@link ng.$exceptionHandler} to rethrow or to log errors passed
- * into the `$exceptionHandler`.
+ * Configures the mock implementation of {@link ng.$exceptionHandler} to rethrow or to log errors
+ * passed into the `$exceptionHandler`.
*/
/**
- * @ngdoc object
- * @name ngMock.$exceptionHandler
+ * @ngdoc service
+ * @name $exceptionHandler
*
* @description
* Mock implementation of {@link ng.$exceptionHandler} that rethrows or logs errors passed
@@ -204,7 +202,7 @@ angular.mock.$Browser.prototype = {
* information.
*
*
- * <pre>
+ * ```js
* describe('$exceptionHandlerProvider', function() {
*
* it('should capture log messages and exceptions', function() {
@@ -225,7 +223,7 @@ angular.mock.$Browser.prototype = {
* });
* });
* });
- * </pre>
+ * ```
*/
angular.mock.$ExceptionHandlerProvider = function() {
@@ -233,8 +231,7 @@ angular.mock.$ExceptionHandlerProvider = function() {
/**
* @ngdoc method
- * @name ngMock.$exceptionHandlerProvider#mode
- * @methodOf ngMock.$exceptionHandlerProvider
+ * @name $exceptionHandlerProvider#mode
*
* @description
* Sets the logging mode.
@@ -244,10 +241,10 @@ angular.mock.$ExceptionHandlerProvider = function() {
* - `rethrow`: If any errors are passed into the handler in tests, it typically
* means that there is a bug in the application or test, so this mock will
* make these tests fail.
- * - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log` mode stores an
- * array of errors in `$exceptionHandler.errors`, to allow later assertion of them.
- * See {@link ngMock.$log#assertEmpty assertEmpty()} and
- * {@link ngMock.$log#reset reset()}
+ * - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log`
+ * mode stores an array of errors in `$exceptionHandler.errors`, to allow later
+ * assertion of them. See {@link ngMock.$log#assertEmpty assertEmpty()} and
+ * {@link ngMock.$log#reset reset()}
*/
this.mode = function(mode) {
switch(mode) {
@@ -270,7 +267,7 @@ angular.mock.$ExceptionHandlerProvider = function() {
handler.errors = errors;
break;
default:
- throw Error("Unknown mode '" + mode + "', only 'log'/'rethrow' modes are allowed!");
+ throw new Error("Unknown mode '" + mode + "', only 'log'/'rethrow' modes are allowed!");
}
};
@@ -284,7 +281,7 @@ angular.mock.$ExceptionHandlerProvider = function() {
/**
* @ngdoc service
- * @name ngMock.$log
+ * @name $log
*
* @description
* Mock implementation of {@link ng.$log} that gathers all logged messages in arrays
@@ -293,24 +290,37 @@ angular.mock.$ExceptionHandlerProvider = function() {
*
*/
angular.mock.$LogProvider = function() {
+ var debug = true;
function concat(array1, array2, index) {
return array1.concat(Array.prototype.slice.call(array2, index));
}
+ this.debugEnabled = function(flag) {
+ if (angular.isDefined(flag)) {
+ debug = flag;
+ return this;
+ } else {
+ return debug;
+ }
+ };
this.$get = function () {
var $log = {
log: function() { $log.log.logs.push(concat([], arguments, 0)); },
warn: function() { $log.warn.logs.push(concat([], arguments, 0)); },
info: function() { $log.info.logs.push(concat([], arguments, 0)); },
- error: function() { $log.error.logs.push(concat([], arguments, 0)); }
+ error: function() { $log.error.logs.push(concat([], arguments, 0)); },
+ debug: function() {
+ if (debug) {
+ $log.debug.logs.push(concat([], arguments, 0));
+ }
+ }
};
/**
* @ngdoc method
- * @name ngMock.$log#reset
- * @methodOf ngMock.$log
+ * @name $log#reset
*
* @description
* Reset all of the logging arrays to empty.
@@ -318,86 +328,97 @@ angular.mock.$LogProvider = function() {
$log.reset = function () {
/**
* @ngdoc property
- * @name ngMock.$log#log.logs
- * @propertyOf ngMock.$log
+ * @name $log#log.logs
*
* @description
* Array of messages logged using {@link ngMock.$log#log}.
*
* @example
- * <pre>
+ * ```js
* $log.log('Some Log');
* var first = $log.log.logs.unshift();
- * </pre>
+ * ```
*/
$log.log.logs = [];
/**
* @ngdoc property
- * @name ngMock.$log#warn.logs
- * @propertyOf ngMock.$log
+ * @name $log#info.logs
*
* @description
- * Array of messages logged using {@link ngMock.$log#warn}.
+ * Array of messages logged using {@link ngMock.$log#info}.
*
* @example
- * <pre>
- * $log.warn('Some Warning');
- * var first = $log.warn.logs.unshift();
- * </pre>
+ * ```js
+ * $log.info('Some Info');
+ * var first = $log.info.logs.unshift();
+ * ```
*/
- $log.warn.logs = [];
+ $log.info.logs = [];
/**
* @ngdoc property
- * @name ngMock.$log#info.logs
- * @propertyOf ngMock.$log
+ * @name $log#warn.logs
*
* @description
- * Array of messages logged using {@link ngMock.$log#info}.
+ * Array of messages logged using {@link ngMock.$log#warn}.
*
* @example
- * <pre>
- * $log.info('Some Info');
- * var first = $log.info.logs.unshift();
- * </pre>
+ * ```js
+ * $log.warn('Some Warning');
+ * var first = $log.warn.logs.unshift();
+ * ```
*/
- $log.info.logs = [];
+ $log.warn.logs = [];
/**
* @ngdoc property
- * @name ngMock.$log#error.logs
- * @propertyOf ngMock.$log
+ * @name $log#error.logs
*
* @description
* Array of messages logged using {@link ngMock.$log#error}.
*
* @example
- * <pre>
- * $log.log('Some Error');
+ * ```js
+ * $log.error('Some Error');
* var first = $log.error.logs.unshift();
- * </pre>
+ * ```
*/
$log.error.logs = [];
+ /**
+ * @ngdoc property
+ * @name $log#debug.logs
+ *
+ * @description
+ * Array of messages logged using {@link ngMock.$log#debug}.
+ *
+ * @example
+ * ```js
+ * $log.debug('Some Error');
+ * var first = $log.debug.logs.unshift();
+ * ```
+ */
+ $log.debug.logs = [];
};
/**
* @ngdoc method
- * @name ngMock.$log#assertEmpty
- * @methodOf ngMock.$log
+ * @name $log#assertEmpty
*
* @description
- * Assert that the all of the logging methods have no logged messages. If messages present, an exception is thrown.
+ * Assert that the all of the logging methods have no logged messages. If messages present, an
+ * exception is thrown.
*/
$log.assertEmpty = function() {
var errors = [];
- angular.forEach(['error', 'warn', 'info', 'log'], function(logLevel) {
+ angular.forEach(['error', 'warn', 'info', 'log', 'debug'], function(logLevel) {
angular.forEach($log[logLevel].logs, function(log) {
angular.forEach(log, function (logItem) {
- errors.push('MOCK $log (' + logLevel + '): ' + String(logItem) + '\n' + (logItem.stack || ''));
+ errors.push('MOCK $log (' + logLevel + '): ' + String(logItem) + '\n' +
+ (logItem.stack || ''));
});
});
});
if (errors.length) {
- errors.unshift("Expected $log to be empty! Either a message was logged unexpectedly, or an expected " +
- "log message was not checked and removed:");
+ errors.unshift("Expected $log to be empty! Either a message was logged unexpectedly, or "+
+ "an expected log message was not checked and removed:");
errors.push('');
throw new Error(errors.join('\n---------\n'));
}
@@ -409,202 +430,381 @@ angular.mock.$LogProvider = function() {
};
-(function() {
- var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
+/**
+ * @ngdoc service
+ * @name $interval
+ *
+ * @description
+ * Mock implementation of the $interval service.
+ *
+ * Use {@link ngMock.$interval#flush `$interval.flush(millis)`} to
+ * move forward by `millis` milliseconds and trigger any functions scheduled to run in that
+ * time.
+ *
+ * @param {function()} fn A function that should be called repeatedly.
+ * @param {number} delay Number of milliseconds between each function call.
+ * @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat
+ * indefinitely.
+ * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
+ * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
+ * @returns {promise} A promise which will be notified on each iteration.
+ */
+angular.mock.$IntervalProvider = function() {
+ this.$get = ['$rootScope', '$q',
+ function($rootScope, $q) {
+ var repeatFns = [],
+ nextRepeatId = 0,
+ now = 0;
+
+ var $interval = function(fn, delay, count, invokeApply) {
+ var deferred = $q.defer(),
+ promise = deferred.promise,
+ iteration = 0,
+ skipApply = (angular.isDefined(invokeApply) && !invokeApply);
+
+ count = (angular.isDefined(count)) ? count : 0,
+ promise.then(null, null, fn);
+
+ promise.$$intervalId = nextRepeatId;
+
+ function tick() {
+ deferred.notify(iteration++);
+
+ if (count > 0 && iteration >= count) {
+ var fnIndex;
+ deferred.resolve(iteration);
+
+ angular.forEach(repeatFns, function(fn, index) {
+ if (fn.id === promise.$$intervalId) fnIndex = index;
+ });
+
+ if (fnIndex !== undefined) {
+ repeatFns.splice(fnIndex, 1);
+ }
+ }
+
+ if (!skipApply) $rootScope.$apply();
+ }
+
+ repeatFns.push({
+ nextTime:(now + delay),
+ delay: delay,
+ fn: tick,
+ id: nextRepeatId,
+ deferred: deferred
+ });
+ repeatFns.sort(function(a,b){ return a.nextTime - b.nextTime;});
+
+ nextRepeatId++;
+ return promise;
+ };
+ /**
+ * @ngdoc method
+ * @name $interval#cancel
+ *
+ * @description
+ * Cancels a task associated with the `promise`.
+ *
+ * @param {number} promise A promise from calling the `$interval` function.
+ * @returns {boolean} Returns `true` if the task was successfully cancelled.
+ */
+ $interval.cancel = function(promise) {
+ if(!promise) return false;
+ var fnIndex;
+
+ angular.forEach(repeatFns, function(fn, index) {
+ if (fn.id === promise.$$intervalId) fnIndex = index;
+ });
+
+ if (fnIndex !== undefined) {
+ repeatFns[fnIndex].deferred.reject('canceled');
+ repeatFns.splice(fnIndex, 1);
+ return true;
+ }
- function jsonStringToDate(string) {
- var match;
- if (match = string.match(R_ISO8061_STR)) {
- var date = new Date(0),
- tzHour = 0,
- tzMin = 0;
- if (match[9]) {
- tzHour = int(match[9] + match[10]);
- tzMin = int(match[9] + match[11]);
+ return false;
+ };
+
+ /**
+ * @ngdoc method
+ * @name $interval#flush
+ * @description
+ *
+ * Runs interval tasks scheduled to be run in the next `millis` milliseconds.
+ *
+ * @param {number=} millis maximum timeout amount to flush up until.
+ *
+ * @return {number} The amount of time moved forward.
+ */
+ $interval.flush = function(millis) {
+ now += millis;
+ while (repeatFns.length && repeatFns[0].nextTime <= now) {
+ var task = repeatFns[0];
+ task.fn();
+ task.nextTime += task.delay;
+ repeatFns.sort(function(a,b){ return a.nextTime - b.nextTime;});
}
- date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3]));
- date.setUTCHours(int(match[4]||0) - tzHour, int(match[5]||0) - tzMin, int(match[6]||0), int(match[7]||0));
- return date;
+ return millis;
+ };
+
+ return $interval;
+ }];
+};
+
+
+/* jshint -W101 */
+/* The R_ISO8061_STR regex is never going to fit into the 100 char limit!
+ * This directive should go inside the anonymous function but a bug in JSHint means that it would
+ * not be enacted early enough to prevent the warning.
+ */
+var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
+
+function jsonStringToDate(string) {
+ var match;
+ if (match = string.match(R_ISO8061_STR)) {
+ var date = new Date(0),
+ tzHour = 0,
+ tzMin = 0;
+ if (match[9]) {
+ tzHour = int(match[9] + match[10]);
+ tzMin = int(match[9] + match[11]);
}
- return string;
+ date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3]));
+ date.setUTCHours(int(match[4]||0) - tzHour,
+ int(match[5]||0) - tzMin,
+ int(match[6]||0),
+ int(match[7]||0));
+ return date;
}
+ return string;
+}
+
+function int(str) {
+ return parseInt(str, 10);
+}
- function int(str) {
- return parseInt(str, 10);
+function padNumber(num, digits, trim) {
+ var neg = '';
+ if (num < 0) {
+ neg = '-';
+ num = -num;
}
+ num = '' + num;
+ while(num.length < digits) num = '0' + num;
+ if (trim)
+ num = num.substr(num.length - digits);
+ return neg + num;
+}
- function padNumber(num, digits, trim) {
- var neg = '';
- if (num < 0) {
- neg = '-';
- num = -num;
- }
- num = '' + num;
- while(num.length < digits) num = '0' + num;
- if (trim)
- num = num.substr(num.length - digits);
- return neg + num;
+
+/**
+ * @ngdoc type
+ * @name angular.mock.TzDate
+ * @description
+ *
+ * *NOTE*: this is not an injectable instance, just a globally available mock class of `Date`.
+ *
+ * Mock of the Date type which has its timezone specified via constructor arg.
+ *
+ * The main purpose is to create Date-like instances with timezone fixed to the specified timezone
+ * offset, so that we can test code that depends on local timezone settings without dependency on
+ * the time zone settings of the machine where the code is running.
+ *
+ * @param {number} offset Offset of the *desired* timezone in hours (fractions will be honored)
+ * @param {(number|string)} timestamp Timestamp representing the desired time in *UTC*
+ *
+ * @example
+ * !!!! WARNING !!!!!
+ * This is not a complete Date object so only methods that were implemented can be called safely.
+ * To make matters worse, TzDate instances inherit stuff from Date via a prototype.
+ *
+ * We do our best to intercept calls to "unimplemented" methods, but since the list of methods is
+ * incomplete we might be missing some non-standard methods. This can result in errors like:
+ * "Date.prototype.foo called on incompatible Object".
+ *
+ * ```js
+ * var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z');
+ * newYearInBratislava.getTimezoneOffset() => -60;
+ * newYearInBratislava.getFullYear() => 2010;
+ * newYearInBratislava.getMonth() => 0;
+ * newYearInBratislava.getDate() => 1;
+ * newYearInBratislava.getHours() => 0;
+ * newYearInBratislava.getMinutes() => 0;
+ * newYearInBratislava.getSeconds() => 0;
+ * ```
+ *
+ */
+angular.mock.TzDate = function (offset, timestamp) {
+ var self = new Date(0);
+ if (angular.isString(timestamp)) {
+ var tsStr = timestamp;
+
+ self.origDate = jsonStringToDate(timestamp);
+
+ timestamp = self.origDate.getTime();
+ if (isNaN(timestamp))
+ throw {
+ name: "Illegal Argument",
+ message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string"
+ };
+ } else {
+ self.origDate = new Date(timestamp);
}
+ var localOffset = new Date(timestamp).getTimezoneOffset();
+ self.offsetDiff = localOffset*60*1000 - offset*1000*60*60;
+ self.date = new Date(timestamp + self.offsetDiff);
- /**
- * @ngdoc object
- * @name angular.mock.TzDate
- * @description
- *
- * *NOTE*: this is not an injectable instance, just a globally available mock class of `Date`.
- *
- * Mock of the Date type which has its timezone specified via constructor arg.
- *
- * The main purpose is to create Date-like instances with timezone fixed to the specified timezone
- * offset, so that we can test code that depends on local timezone settings without dependency on
- * the time zone settings of the machine where the code is running.
- *
- * @param {number} offset Offset of the *desired* timezone in hours (fractions will be honored)
- * @param {(number|string)} timestamp Timestamp representing the desired time in *UTC*
- *
- * @example
- * !!!! WARNING !!!!!
- * This is not a complete Date object so only methods that were implemented can be called safely.
- * To make matters worse, TzDate instances inherit stuff from Date via a prototype.
- *
- * We do our best to intercept calls to "unimplemented" methods, but since the list of methods is
- * incomplete we might be missing some non-standard methods. This can result in errors like:
- * "Date.prototype.foo called on incompatible Object".
- *
- * <pre>
- * var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z');
- * newYearInBratislava.getTimezoneOffset() => -60;
- * newYearInBratislava.getFullYear() => 2010;
- * newYearInBratislava.getMonth() => 0;
- * newYearInBratislava.getDate() => 1;
- * newYearInBratislava.getHours() => 0;
- * newYearInBratislava.getMinutes() => 0;
- * </pre>
- *
- */
- angular.mock.TzDate = function (offset, timestamp) {
- var self = new Date(0);
- if (angular.isString(timestamp)) {
- var tsStr = timestamp;
-
- self.origDate = jsonStringToDate(timestamp);
-
- timestamp = self.origDate.getTime();
- if (isNaN(timestamp))
- throw {
- name: "Illegal Argument",
- message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string"
- };
- } else {
- self.origDate = new Date(timestamp);
- }
+ self.getTime = function() {
+ return self.date.getTime() - self.offsetDiff;
+ };
- var localOffset = new Date(timestamp).getTimezoneOffset();
- self.offsetDiff = localOffset*60*1000 - offset*1000*60*60;
- self.date = new Date(timestamp + self.offsetDiff);
+ self.toLocaleDateString = function() {
+ return self.date.toLocaleDateString();
+ };
- self.getTime = function() {
- return self.date.getTime() - self.offsetDiff;
- };
+ self.getFullYear = function() {
+ return self.date.getFullYear();
+ };
- self.toLocaleDateString = function() {
- return self.date.toLocaleDateString();
- };
+ self.getMonth = function() {
+ return self.date.getMonth();
+ };
- self.getFullYear = function() {
- return self.date.getFullYear();
- };
+ self.getDate = function() {
+ return self.date.getDate();
+ };
- self.getMonth = function() {
- return self.date.getMonth();
- };
+ self.getHours = function() {
+ return self.date.getHours();
+ };
- self.getDate = function() {
- return self.date.getDate();
- };
+ self.getMinutes = function() {
+ return self.date.getMinutes();
+ };
- self.getHours = function() {
- return self.date.getHours();
- };
+ self.getSeconds = function() {
+ return self.date.getSeconds();
+ };
- self.getMinutes = function() {
- return self.date.getMinutes();
- };
+ self.getMilliseconds = function() {
+ return self.date.getMilliseconds();
+ };
- self.getSeconds = function() {
- return self.date.getSeconds();
- };
+ self.getTimezoneOffset = function() {
+ return offset * 60;
+ };
- self.getTimezoneOffset = function() {
- return offset * 60;
- };
+ self.getUTCFullYear = function() {
+ return self.origDate.getUTCFullYear();
+ };
- self.getUTCFullYear = function() {
- return self.origDate.getUTCFullYear();
- };
+ self.getUTCMonth = function() {
+ return self.origDate.getUTCMonth();
+ };
- self.getUTCMonth = function() {
- return self.origDate.getUTCMonth();
- };
+ self.getUTCDate = function() {
+ return self.origDate.getUTCDate();
+ };
- self.getUTCDate = function() {
- return self.origDate.getUTCDate();
- };
+ self.getUTCHours = function() {
+ return self.origDate.getUTCHours();
+ };
- self.getUTCHours = function() {
- return self.origDate.getUTCHours();
- };
+ self.getUTCMinutes = function() {
+ return self.origDate.getUTCMinutes();
+ };
- self.getUTCMinutes = function() {
- return self.origDate.getUTCMinutes();
- };
+ self.getUTCSeconds = function() {
+ return self.origDate.getUTCSeconds();
+ };
- self.getUTCSeconds = function() {
- return self.origDate.getUTCSeconds();
- };
+ self.getUTCMilliseconds = function() {
+ return self.origDate.getUTCMilliseconds();
+ };
- self.getUTCMilliseconds = function() {
- return self.origDate.getUTCMilliseconds();
+ self.getDay = function() {
+ return self.date.getDay();
+ };
+
+ // provide this method only on browsers that already have it
+ if (self.toISOString) {
+ self.toISOString = function() {
+ return padNumber(self.origDate.getUTCFullYear(), 4) + '-' +
+ padNumber(self.origDate.getUTCMonth() + 1, 2) + '-' +
+ padNumber(self.origDate.getUTCDate(), 2) + 'T' +
+ padNumber(self.origDate.getUTCHours(), 2) + ':' +
+ padNumber(self.origDate.getUTCMinutes(), 2) + ':' +
+ padNumber(self.origDate.getUTCSeconds(), 2) + '.' +
+ padNumber(self.origDate.getUTCMilliseconds(), 3) + 'Z';
};
+ }
- self.getDay = function() {
- return self.date.getDay();
+ //hide all methods not implemented in this mock that the Date prototype exposes
+ var unimplementedMethods = ['getUTCDay',
+ 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
+ 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',
+ 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',
+ 'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString',
+ 'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];
+
+ angular.forEach(unimplementedMethods, function(methodName) {
+ self[methodName] = function() {
+ throw new Error("Method '" + methodName + "' is not implemented in the TzDate mock");
};
+ });
- // provide this method only on browsers that already have it
- if (self.toISOString) {
- self.toISOString = function() {
- return padNumber(self.origDate.getUTCFullYear(), 4) + '-' +
- padNumber(self.origDate.getUTCMonth() + 1, 2) + '-' +
- padNumber(self.origDate.getUTCDate(), 2) + 'T' +
- padNumber(self.origDate.getUTCHours(), 2) + ':' +
- padNumber(self.origDate.getUTCMinutes(), 2) + ':' +
- padNumber(self.origDate.getUTCSeconds(), 2) + '.' +
- padNumber(self.origDate.getUTCMilliseconds(), 3) + 'Z'
- }
- }
+ return self;
+};
+
+//make "tzDateInstance instanceof Date" return true
+angular.mock.TzDate.prototype = Date.prototype;
+/* jshint +W101 */
+
+angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
- //hide all methods not implemented in this mock that the Date prototype exposes
- var unimplementedMethods = ['getMilliseconds', 'getUTCDay',
- 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
- 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',
- 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',
- 'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString',
- 'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];
-
- angular.forEach(unimplementedMethods, function(methodName) {
- self[methodName] = function() {
- throw Error("Method '" + methodName + "' is not implemented in the TzDate mock");
+ .config(['$provide', function($provide) {
+
+ var reflowQueue = [];
+ $provide.value('$$animateReflow', function(fn) {
+ var index = reflowQueue.length;
+ reflowQueue.push(fn);
+ return function cancel() {
+ reflowQueue.splice(index, 1);
};
});
- return self;
- };
+ $provide.decorator('$animate', function($delegate, $$asyncCallback) {
+ var animate = {
+ queue : [],
+ enabled : $delegate.enabled,
+ triggerCallbacks : function() {
+ $$asyncCallback.flush();
+ },
+ triggerReflow : function() {
+ angular.forEach(reflowQueue, function(fn) {
+ fn();
+ });
+ reflowQueue = [];
+ }
+ };
+
+ angular.forEach(
+ ['enter','leave','move','addClass','removeClass','setClass'], function(method) {
+ animate[method] = function() {
+ animate.queue.push({
+ event : method,
+ element : arguments[0],
+ args : arguments
+ });
+ $delegate[method].apply($delegate, arguments);
+ };
+ });
+
+ return animate;
+ });
- //make "tzDateInstance instanceof Date" return true
- angular.mock.TzDate.prototype = Date.prototype;
-})();
+ }]);
/**
@@ -614,9 +814,11 @@ angular.mock.$LogProvider = function() {
*
* *NOTE*: this is not an injectable instance, just a globally available function.
*
- * Method for serializing common angular objects (scope, elements, etc..) into strings, useful for debugging.
+ * Method for serializing common angular objects (scope, elements, etc..) into strings, useful for
+ * debugging.
*
- * This method is also available on window, where it can be used to display objects on debug console.
+ * This method is also available on window, where it can be used to display objects on debug
+ * console.
*
* @param {*} object - any object to turn into string.
* @return {string} a serialized string of the argument
@@ -646,6 +848,8 @@ angular.mock.dump = function(object) {
} else if (object instanceof Error) {
out = object.stack || ('' + object.name + ': ' + object.message);
} else {
+ // TODO(i): this prevents methods being logged,
+ // we should have a better way to serialize objects
out = angular.toJson(object, true);
}
} else {
@@ -659,7 +863,7 @@ angular.mock.dump = function(object) {
offset = offset || ' ';
var log = [offset + 'Scope(' + scope.$id + '): {'];
for ( var key in scope ) {
- if (scope.hasOwnProperty(key) && !key.match(/^(\$|this)/)) {
+ if (Object.prototype.hasOwnProperty.call(scope, key) && !key.match(/^(\$|this)/)) {
log.push(' ' + key + ': ' + angular.toJson(scope[key]));
}
}
@@ -674,8 +878,8 @@ angular.mock.dump = function(object) {
};
/**
- * @ngdoc object
- * @name ngMock.$httpBackend
+ * @ngdoc service
+ * @name $httpBackend
* @description
* Fake HTTP backend implementation suitable for unit testing applications that use the
* {@link ng.$http $http service}.
@@ -684,8 +888,8 @@ angular.mock.dump = function(object) {
* development please see {@link ngMockE2E.$httpBackend e2e $httpBackend mock}.
*
* During unit testing, we want our unit tests to run quickly and have no external dependencies so
- * we don’t want to send {@link https://developer.mozilla.org/en/xmlhttprequest XHR} or
- * {@link http://en.wikipedia.org/wiki/JSONP JSONP} requests to a real server. All we really need is
+ * we don’t want to send [XHR](https://developer.mozilla.org/en/xmlhttprequest) or
+ * [JSONP](http://en.wikipedia.org/wiki/JSONP) requests to a real server. All we really need is
* to verify whether a certain request has been sent or not, or alternatively just let the
* application make requests, respond with pre-trained responses and assert that the end result is
* what we expect it to be.
@@ -763,20 +967,20 @@ angular.mock.dump = function(object) {
*
* # Flushing HTTP requests
*
- * The $httpBackend used in production, always responds to requests with responses asynchronously.
- * If we preserved this behavior in unit testing, we'd have to create async unit tests, which are
- * hard to write, follow and maintain. At the same time the testing mock, can't respond
+ * The $httpBackend used in production always responds to requests with responses asynchronously.
+ * If we preserved this behavior in unit testing we'd have to create async unit tests, which are
+ * hard to write, understand, and maintain. However, the testing mock can't respond
* synchronously because that would change the execution of the code under test. For this reason the
* mock $httpBackend has a `flush()` method, which allows the test to explicitly flush pending
- * requests and thus preserving the async api of the backend, while allowing the test to execute
+ * requests and thus preserve the async api of the backend while allowing the test to execute
* synchronously.
*
*
* # Unit testing with mock $httpBackend
- * The following code shows how to setup and use the mock backend in unit testing a controller.
- * First we create the controller under test
+ * The following code shows how to setup and use the mock backend when unit testing a controller.
+ * First we create the controller under test:
*
- <pre>
+ ```js
// The controller code
function MyController($scope, $http) {
var authToken;
@@ -797,11 +1001,11 @@ angular.mock.dump = function(object) {
});
};
}
- </pre>
+ ```
*
- * Now we setup the mock backend and create the test specs.
+ * Now we setup the mock backend and create the test specs:
*
- <pre>
+ ```js
// testing controller
describe('MyController', function() {
var $httpBackend, $rootScope, createController;
@@ -867,10 +1071,10 @@ angular.mock.dump = function(object) {
$httpBackend.flush();
});
});
- </pre>
+ ```
*/
angular.mock.$HttpBackendProvider = function() {
- this.$get = [createHttpBackendMock];
+ this.$get = ['