Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4224cd5

Browse files
committed
fix(mocks): rename mock.animate to ngAnimateMock and ensure it contains all test helper code for ngAnimate
Closes #5822 Closes #5917
1 parent 906fdad commit 4224cd5

10 files changed

+26
-39
lines changed

src/ngMock/angular-mocks.js

+13-27
Original file line numberDiff line numberDiff line change
@@ -757,43 +757,29 @@ angular.mock.TzDate = function (offset, timestamp) {
757757
angular.mock.TzDate.prototype = Date.prototype;
758758
/* jshint +W101 */
759759

760-
// TODO(matias): remove this IMMEDIATELY once we can properly detect the
761-
// presence of a registered module
762-
var animateLoaded;
763-
try {
764-
angular.module('ngAnimate');
765-
animateLoaded = true;
766-
} catch(e) {}
767-
768-
if(animateLoaded) {
769-
angular.module('ngAnimate').config(['$provide', function($provide) {
760+
angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
761+
762+
.config(['$provide', function($provide) {
770763
var reflowQueue = [];
764+
771765
$provide.value('$$animateReflow', function(fn) {
772766
reflowQueue.push(fn);
773767
return angular.noop;
774768
});
775-
$provide.decorator('$animate', function($delegate) {
776-
$delegate.triggerReflow = function() {
777-
if(reflowQueue.length === 0) {
778-
throw new Error('No animation reflows present');
779-
}
780-
angular.forEach(reflowQueue, function(fn) {
781-
fn();
782-
});
783-
reflowQueue = [];
784-
};
785-
return $delegate;
786-
});
787-
}]);
788-
}
789769

790-
angular.mock.animate = angular.module('mock.animate', ['ng'])
791-
792-
.config(['$provide', function($provide) {
793770
$provide.decorator('$animate', function($delegate) {
794771
var animate = {
795772
queue : [],
796773
enabled : $delegate.enabled,
774+
triggerReflow : function() {
775+
if(reflowQueue.length === 0) {
776+
throw new Error('No animation reflows present');
777+
}
778+
angular.forEach(reflowQueue, function(fn) {
779+
fn();
780+
});
781+
reflowQueue = [];
782+
}
797783
};
798784

799785
angular.forEach(['enter','leave','move','addClass','removeClass'], function(method) {

test/ng/compileSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4490,7 +4490,7 @@ describe('$compile', function() {
44904490

44914491
describe('$animate animation hooks', function() {
44924492

4493-
beforeEach(module('mock.animate'));
4493+
beforeEach(module('ngAnimateMock'));
44944494

44954495
it('should automatically fire the addClass and removeClass animation hooks',
44964496
inject(function($compile, $animate, $rootScope) {

test/ng/directive/ngClassSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ describe('ngClass animations', function() {
309309
var body, element, $rootElement;
310310

311311
it("should avoid calling addClass accidentally when removeClass is going on", function() {
312-
module('mock.animate');
312+
module('ngAnimateMock');
313313
inject(function($compile, $rootScope, $animate, $timeout) {
314314
var element = angular.element('<div ng-class="val"></div>');
315315
var body = jqLite(document.body);
@@ -416,7 +416,7 @@ describe('ngClass animations', function() {
416416
});
417417

418418
it("should not remove classes if they're going to be added back right after", function() {
419-
module('mock.animate');
419+
module('ngAnimateMock');
420420

421421
inject(function($rootScope, $compile, $animate) {
422422
var className;

test/ng/directive/ngIfSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe('ngIf animations', function () {
210210
return element;
211211
}
212212

213-
beforeEach(module('mock.animate'));
213+
beforeEach(module('ngAnimateMock'));
214214

215215
beforeEach(module(function() {
216216
// we need to run animation on attached elements;

test/ng/directive/ngIncludeSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ describe('ngInclude', function() {
353353
};
354354
}
355355

356-
beforeEach(module(spyOnAnchorScroll(), 'mock.animate'));
356+
beforeEach(module(spyOnAnchorScroll(), 'ngAnimateMock'));
357357
beforeEach(inject(
358358
putIntoCache('template.html', 'CONTENT'),
359359
putIntoCache('another.html', 'CONTENT')));
@@ -589,7 +589,7 @@ describe('ngInclude animations', function() {
589589
dealoc(element);
590590
});
591591

592-
beforeEach(module('mock.animate'));
592+
beforeEach(module('ngAnimateMock'));
593593

594594
afterEach(function(){
595595
dealoc(element);

test/ng/directive/ngRepeatSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ describe('ngRepeat animations', function() {
11491149
return element;
11501150
}
11511151

1152-
beforeEach(module('mock.animate'));
1152+
beforeEach(module('ngAnimateMock'));
11531153

11541154
beforeEach(module(function() {
11551155
// we need to run animation on attached elements;

test/ng/directive/ngShowHideSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('ngShow / ngHide animations', function() {
7373
body.removeAttr('ng-animation-running');
7474
});
7575

76-
beforeEach(module('mock.animate'));
76+
beforeEach(module('ngAnimateMock'));
7777

7878
beforeEach(module(function($animateProvider, $provide) {
7979
return function(_$rootElement_) {

test/ng/directive/ngSwitchSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ describe('ngSwitch animations', function() {
223223
return element;
224224
}
225225

226-
beforeEach(module('mock.animate'));
226+
beforeEach(module('ngAnimateMock'));
227227

228228
beforeEach(module(function() {
229229
// we need to run animation on attached elements;

test/ngAnimate/animateSpec.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
describe("ngAnimate", function() {
44

55
beforeEach(module('ngAnimate'));
6+
beforeEach(module('ngAnimateMock'));
67

78

89
it("should disable animations on bootstrap for structural animations even after the first digest has passed", function() {

test/ngRoute/directive/ngViewSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ describe('ngView animations', function() {
684684

685685
describe('hooks', function() {
686686
beforeEach(module('ngAnimate'));
687-
beforeEach(module('mock.animate'));
687+
beforeEach(module('ngAnimateMock'));
688688

689689
it('should fire off the enter animation',
690690
inject(function($compile, $rootScope, $location, $timeout, $animate) {
@@ -702,7 +702,7 @@ describe('ngView animations', function() {
702702

703703
var item;
704704
$templateCache.put('/foo.html', [200, '<div>foo</div>', {}]);
705-
element = $compile(html('<ng-view></div>'))($rootScope);
705+
element = $compile(html('<div ng-view></div>'))($rootScope);
706706

707707
$location.path('/foo');
708708
$rootScope.$digest();
@@ -863,7 +863,7 @@ describe('ngView animations', function() {
863863
};
864864
}
865865

866-
beforeEach(module(spyOnAnchorScroll(), 'mock.animate'));
866+
beforeEach(module(spyOnAnchorScroll(), 'ngAnimateMock'));
867867
beforeEach(inject(spyOnAnimateEnter()));
868868

869869
it('should call $anchorScroll if autoscroll attribute is present', inject(

0 commit comments

Comments
 (0)