Skip to content

Commit 1413328

Browse files
committed
fix(ngMock): ensure ngAnimate isn't a required mock
1 parent 7d09bd3 commit 1413328

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/ngMock/angular-mocks.js

+29-19
Original file line numberDiff line numberDiff line change
@@ -756,25 +756,35 @@ angular.mock.TzDate = function (offset, timestamp) {
756756
angular.mock.TzDate.prototype = Date.prototype;
757757
/* jshint +W101 */
758758

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

779789
angular.mock.animate = angular.module('mock.animate', ['ng'])
780790

0 commit comments

Comments
 (0)