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

Commit

Permalink
fix(mocks): rename mock.animate to ngAnimateMock and ensure it contai…
Browse files Browse the repository at this point in the history
…ns all test helper code for ngAnimate

Closes #5822
Closes #5917
  • Loading branch information
matsko committed Feb 6, 2014
1 parent 906fdad commit 4224cd5
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 39 deletions.
40 changes: 13 additions & 27 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/ng/directive/ngClassSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div ng-class="val"></div>');
var body = jqLite(document.body);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/ng/directive/ngIfSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/ng/directive/ngIncludeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down Expand Up @@ -589,7 +589,7 @@ describe('ngInclude animations', function() {
dealoc(element);
});

beforeEach(module('mock.animate'));
beforeEach(module('ngAnimateMock'));

afterEach(function(){
dealoc(element);
Expand Down
2 changes: 1 addition & 1 deletion test/ng/directive/ngRepeatSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/ng/directive/ngShowHideSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
2 changes: 1 addition & 1 deletion test/ng/directive/ngSwitchSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions test/ngRoute/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -702,7 +702,7 @@ describe('ngView animations', function() {

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

$location.path('/foo');
$rootScope.$digest();
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4224cd5

Please sign in to comment.