From 7ce4a3f882cd6232a5e63f528cd501ed931333c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Wed, 22 Jan 2014 19:28:42 -0500 Subject: [PATCH] fix(mocks): ensure mock.animate contains all test helper code for ngAnimate Closes #5822 Closes #5917 --- src/ngMock/angular-mocks.js | 40 +++++++++------------------- test/ng/compileSpec.js | 2 +- test/ng/directive/ngClassSpec.js | 4 +-- test/ng/directive/ngIfSpec.js | 2 +- test/ng/directive/ngIncludeSpec.js | 4 +-- test/ng/directive/ngRepeatSpec.js | 2 +- test/ng/directive/ngShowHideSpec.js | 2 +- test/ng/directive/ngSwitchSpec.js | 2 +- test/ngAnimate/animateSpec.js | 1 + test/ngRoute/directive/ngViewSpec.js | 6 ++--- 10 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 091a8a16d22e..1be07a242b46 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -757,43 +757,29 @@ angular.mock.TzDate = function (offset, timestamp) { 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) {} - -if(animateLoaded) { - angular.module('ngAnimate').config(['$provide', function($provide) { +angular.mock.animate = angular.module('ngAnimateMock', ['ng']) + + .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, + triggerReflow : function() { + if(reflowQueue.length === 0) { + throw new Error('No animation reflows present'); + } + angular.forEach(reflowQueue, function(fn) { + fn(); + }); + reflowQueue = []; + } }; angular.forEach(['enter','leave','move','addClass','removeClass'], function(method) { diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index c8cb70f8c6e5..085eb6e9d552 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -4490,7 +4490,7 @@ describe('$compile', function() { describe('$animate animation hooks', function() { - beforeEach(module('mock.animate')); + beforeEach(module('ngAnimateMock')); it('should automatically fire the addClass and removeClass animation hooks', inject(function($compile, $animate, $rootScope) { diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index 976c0c3f2dc6..b162fea6ce71 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -309,7 +309,7 @@ describe('ngClass animations', function() { var body, element, $rootElement; it("should avoid calling addClass accidentally when removeClass is going on", function() { - module('mock.animate'); + module('ngAnimateMock'); inject(function($compile, $rootScope, $animate, $timeout) { var element = angular.element('
'); var body = jqLite(document.body); @@ -416,7 +416,7 @@ describe('ngClass animations', function() { }); it("should not remove classes if they're going to be added back right after", function() { - module('mock.animate'); + module('ngAnimateMock'); inject(function($rootScope, $compile, $animate) { var className; diff --git a/test/ng/directive/ngIfSpec.js b/test/ng/directive/ngIfSpec.js index 81b541234924..d40e6812019a 100755 --- a/test/ng/directive/ngIfSpec.js +++ b/test/ng/directive/ngIfSpec.js @@ -210,7 +210,7 @@ describe('ngIf animations', function () { return element; } - beforeEach(module('mock.animate')); + beforeEach(module('ngAnimateMock')); beforeEach(module(function() { // we need to run animation on attached elements; diff --git a/test/ng/directive/ngIncludeSpec.js b/test/ng/directive/ngIncludeSpec.js index 380385592cd5..ebb35147045c 100644 --- a/test/ng/directive/ngIncludeSpec.js +++ b/test/ng/directive/ngIncludeSpec.js @@ -353,7 +353,7 @@ describe('ngInclude', function() { }; } - beforeEach(module(spyOnAnchorScroll(), 'mock.animate')); + beforeEach(module(spyOnAnchorScroll(), 'ngAnimateMock')); beforeEach(inject( putIntoCache('template.html', 'CONTENT'), putIntoCache('another.html', 'CONTENT'))); @@ -589,7 +589,7 @@ describe('ngInclude animations', function() { dealoc(element); }); - beforeEach(module('mock.animate')); + beforeEach(module('ngAnimateMock')); afterEach(function(){ dealoc(element); diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 8bcb92831b4b..b672f86f8a7c 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -1149,7 +1149,7 @@ describe('ngRepeat animations', function() { return element; } - beforeEach(module('mock.animate')); + beforeEach(module('ngAnimateMock')); beforeEach(module(function() { // we need to run animation on attached elements; diff --git a/test/ng/directive/ngShowHideSpec.js b/test/ng/directive/ngShowHideSpec.js index 8a25843cfa34..4bbbbb789006 100644 --- a/test/ng/directive/ngShowHideSpec.js +++ b/test/ng/directive/ngShowHideSpec.js @@ -73,7 +73,7 @@ describe('ngShow / ngHide animations', function() { body.removeAttr('ng-animation-running'); }); - beforeEach(module('mock.animate')); + beforeEach(module('ngAnimateMock')); beforeEach(module(function($animateProvider, $provide) { return function(_$rootElement_) { diff --git a/test/ng/directive/ngSwitchSpec.js b/test/ng/directive/ngSwitchSpec.js index a8c91359fb05..e039c4d52932 100644 --- a/test/ng/directive/ngSwitchSpec.js +++ b/test/ng/directive/ngSwitchSpec.js @@ -223,7 +223,7 @@ describe('ngSwitch animations', function() { return element; } - beforeEach(module('mock.animate')); + beforeEach(module('ngAnimateMock')); beforeEach(module(function() { // we need to run animation on attached elements; diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index a5123929167b..d626d60eeaaf 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -3,6 +3,7 @@ describe("ngAnimate", function() { beforeEach(module('ngAnimate')); + beforeEach(module('ngAnimateMock')); it("should disable animations on bootstrap for structural animations even after the first digest has passed", function() { diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js index 113055cbc6ef..9bcd50b385aa 100644 --- a/test/ngRoute/directive/ngViewSpec.js +++ b/test/ngRoute/directive/ngViewSpec.js @@ -684,7 +684,7 @@ describe('ngView animations', function() { describe('hooks', function() { beforeEach(module('ngAnimate')); - beforeEach(module('mock.animate')); + beforeEach(module('ngAnimateMock')); it('should fire off the enter animation', inject(function($compile, $rootScope, $location, $timeout, $animate) { @@ -702,7 +702,7 @@ describe('ngView animations', function() { var item; $templateCache.put('/foo.html', [200, '
foo
', {}]); - element = $compile(html(''))($rootScope); + element = $compile(html('
'))($rootScope); $location.path('/foo'); $rootScope.$digest(); @@ -863,7 +863,7 @@ describe('ngView animations', function() { }; } - beforeEach(module(spyOnAnchorScroll(), 'mock.animate')); + beforeEach(module(spyOnAnchorScroll(), 'ngAnimateMock')); beforeEach(inject(spyOnAnimateEnter())); it('should call $anchorScroll if autoscroll attribute is present', inject(