vendor/assets/javascripts/angular-mocks.js in angular-gem-1.2.12 vs vendor/assets/javascripts/angular-mocks.js in angular-gem-1.2.13

- old
+ new

@@ -1,7 +1,7 @@ /** - * @license AngularJS v1.2.9 + * @license AngularJS v1.2.13 * (c) 2010-2014 Google, Inc. http://angularjs.org * License: MIT */ (function(window, angular, undefined) { @@ -384,11 +384,11 @@ * @description * Array of messages logged using {@link ngMock.$log#error}. * * @example * <pre> - * $log.log('Some Error'); + * $log.error('Some Error'); * var first = $log.error.logs.unshift(); * </pre> */ $log.error.logs = []; /** @@ -509,10 +509,11 @@ nextRepeatId++; return promise; }; $interval.cancel = function(promise) { + if(!promise) return false; var fnIndex; angular.forEach(repeatFns, function(fn, index) { if (fn.id === promise.$$intervalId) fnIndex = index; }); @@ -761,74 +762,44 @@ //make "tzDateInstance instanceof Date" return true angular.mock.TzDate.prototype = Date.prototype; /* jshint +W101 */ -// TODO(matias): remove this IMMEDIATELY once we can properly detect the -// presence of a registered module -var animateLoaded; -try { - angular.module('ngAnimate'); - animateLoaded = true; -} catch(e) {} +angular.mock.animate = angular.module('ngAnimateMock', ['ng']) -if(animateLoaded) { - angular.module('ngAnimate').config(['$provide', function($provide) { + .config(['$provide', function($provide) { var reflowQueue = []; + $provide.value('$$animateReflow', function(fn) { reflowQueue.push(fn); return angular.noop; }); - $provide.decorator('$animate', function($delegate) { - $delegate.triggerReflow = function() { - if(reflowQueue.length === 0) { - throw new Error('No animation reflows present'); - } - angular.forEach(reflowQueue, function(fn) { - fn(); - }); - reflowQueue = []; - }; - return $delegate; - }); - }]); -} -angular.mock.animate = angular.module('mock.animate', ['ng']) - - .config(['$provide', function($provide) { - $provide.decorator('$animate', function($delegate) { var animate = { queue : [], enabled : $delegate.enabled, - flushNext : function(name) { - var tick = animate.queue.shift(); - - if (!tick) throw new Error('No animation to be flushed'); - if(tick.method !== name) { - throw new Error('The next animation is not "' + name + - '", but is "' + tick.method + '"'); + triggerReflow : function() { + if(reflowQueue.length === 0) { + throw new Error('No animation reflows present'); } - tick.fn(); - return tick; + angular.forEach(reflowQueue, function(fn) { + fn(); + }); + reflowQueue = []; } }; - angular.forEach(['enter','leave','move','addClass','removeClass'], function(method) { + angular.forEach( + ['enter','leave','move','addClass','removeClass','setClass'], function(method) { animate[method] = function() { - var params = arguments; animate.queue.push({ - method : method, - params : params, - element : angular.isElement(params[0]) && params[0], - parent : angular.isElement(params[1]) && params[1], - after : angular.isElement(params[2]) && params[2], - fn : function() { - $delegate[method].apply($delegate, params); - } + event : method, + element : arguments[0], + args : arguments }); + $delegate[method].apply($delegate, arguments); }; }); return animate; }); @@ -994,22 +965,22 @@ * the request. The response from the first matched definition is returned. * * * # 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> // The controller code function MyController($scope, $http) { var authToken; @@ -1030,11 +1001,11 @@ }); }; } </pre> * - * Now we setup the mock backend and create the test specs. + * Now we setup the mock backend and create the test specs: * <pre> // testing controller describe('MyController', function() { var $httpBackend, $rootScope, createController; @@ -1734,11 +1705,11 @@ * * The `ngMock` module providers support to inject and mock Angular services into unit tests. * In addition, ngMock also extends various core ng services such that they can be * inspected and controlled in a synchronous manner within test code. * - * {@installModule mocks} + * {@installModule mock} * * <div doc-module-components="ngMock"></div> * */ angular.module('ngMock', ['ng']).provider({ @@ -1952,11 +1923,11 @@ if(window.jasmine || window.mocha) { var currentSpec = null, isSpecRunning = function() { - return currentSpec && (window.mocha || currentSpec.queue.running); + return !!currentSpec; }; beforeEach(function() { currentSpec = this; @@ -2130,10 +2101,10 @@ ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString; window.inject = angular.mock.inject = function() { var blockFns = Array.prototype.slice.call(arguments, 0); var errorForStack = new Error('Declaration Location'); - return isSpecRunning() ? workFn() : workFn; + return isSpecRunning() ? workFn.call(currentSpec) : workFn; ///////////////////// function workFn() { var modules = currentSpec.$modules || []; modules.unshift('ngMock');