1
1
/**
2
- * @license AngularJS v1.5.0-rc.0
3
- * (c) 2010-2015 Google, Inc. http://angularjs.org
2
+ * @license AngularJS v1.5.1-build.4601+sha.c966876
3
+ * (c) 2010-2016 Google, Inc. http://angularjs.org
4
4
* License: MIT
5
5
*/
6
6
( function ( window , angular , undefined ) {
@@ -758,6 +758,15 @@ angular.mock.TzDate = function(offset, timestamp) {
758
758
angular . mock . TzDate . prototype = Date . prototype ;
759
759
/* jshint +W101 */
760
760
761
+
762
+ /**
763
+ * @ngdoc service
764
+ * @name $animate
765
+ *
766
+ * @description
767
+ * Mock implementation of the {@link ng.$animate `$animate`} service. Exposes two additional methods
768
+ * for testing animations.
769
+ */
761
770
angular . mock . animate = angular . module ( 'ngAnimateMock' , [ 'ng' ] )
762
771
763
772
. config ( [ '$provide' , function ( $provide ) {
@@ -790,9 +799,50 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
790
799
return queueFn ;
791
800
} ) ;
792
801
793
- $provide . decorator ( '$animate' , [ '$delegate' , '$timeout' , '$browser' , '$$rAF' ,
802
+ $provide . decorator ( '$$animateJs' , [ '$delegate' , function ( $delegate ) {
803
+ var runners = [ ] ;
804
+
805
+ var animateJsConstructor = function ( ) {
806
+ var animator = $delegate . apply ( $delegate , arguments ) ;
807
+ // If no javascript animation is found, animator is undefined
808
+ if ( animator ) {
809
+ runners . push ( animator ) ;
810
+ }
811
+ return animator ;
812
+ } ;
813
+
814
+ animateJsConstructor . $closeAndFlush = function ( ) {
815
+ runners . forEach ( function ( runner ) {
816
+ runner . end ( ) ;
817
+ } ) ;
818
+ runners = [ ] ;
819
+ } ;
820
+
821
+ return animateJsConstructor ;
822
+ } ] ) ;
823
+
824
+ $provide . decorator ( '$animateCss' , [ '$delegate' , function ( $delegate ) {
825
+ var runners = [ ] ;
826
+
827
+ var animateCssConstructor = function ( element , options ) {
828
+ var animator = $delegate ( element , options ) ;
829
+ runners . push ( animator ) ;
830
+ return animator ;
831
+ } ;
832
+
833
+ animateCssConstructor . $closeAndFlush = function ( ) {
834
+ runners . forEach ( function ( runner ) {
835
+ runner . end ( ) ;
836
+ } ) ;
837
+ runners = [ ] ;
838
+ } ;
839
+
840
+ return animateCssConstructor ;
841
+ } ] ) ;
842
+
843
+ $provide . decorator ( '$animate' , [ '$delegate' , '$timeout' , '$browser' , '$$rAF' , '$animateCss' , '$$animateJs' ,
794
844
'$$forceReflow' , '$$animateAsyncRun' , '$rootScope' ,
795
- function ( $delegate , $timeout , $browser , $$rAF ,
845
+ function ( $delegate , $timeout , $browser , $$rAF , $animateCss , $$animateJs ,
796
846
$$forceReflow , $$animateAsyncRun , $rootScope ) {
797
847
var animate = {
798
848
queue : [ ] ,
@@ -804,7 +854,35 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
804
854
return $$forceReflow . totalReflows ;
805
855
} ,
806
856
enabled : $delegate . enabled ,
807
- flush : function ( ) {
857
+ /**
858
+ * @ngdoc method
859
+ * @name $animate#closeAndFlush
860
+ * @description
861
+ *
862
+ * This method will close all pending animations (both {@link ngAnimate#javascript-based-animations Javascript}
863
+ * and {@link ngAnimate.$animateCss CSS}) and it will also flush any remaining animation frames and/or callbacks.
864
+ */
865
+ closeAndFlush : function ( ) {
866
+ // we allow the flush command to swallow the errors
867
+ // because depending on whether CSS or JS animations are
868
+ // used, there may not be a RAF flush. The primary flush
869
+ // at the end of this function must throw an exception
870
+ // because it will track if there were pending animations
871
+ this . flush ( true ) ;
872
+ $animateCss . $closeAndFlush ( ) ;
873
+ $$animateJs . $closeAndFlush ( ) ;
874
+ this . flush ( ) ;
875
+ } ,
876
+ /**
877
+ * @ngdoc method
878
+ * @name $animate#flush
879
+ * @description
880
+ *
881
+ * This method is used to flush the pending callbacks and animation frames to either start
882
+ * an animation or conclude an animation. Note that this will not actually close an
883
+ * actively running animation (see {@link ngMock.$animate#closeAndFlush `closeAndFlush()`} for that).
884
+ */
885
+ flush : function ( hideErrors ) {
808
886
$rootScope . $digest ( ) ;
809
887
810
888
var doNextRun , somethingFlushed = false ;
@@ -821,7 +899,7 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
821
899
}
822
900
} while ( doNextRun ) ;
823
901
824
- if ( ! somethingFlushed ) {
902
+ if ( ! somethingFlushed && ! hideErrors ) {
825
903
throw new Error ( 'No pending animations ready to be closed or flushed' ) ;
826
904
}
827
905
@@ -1030,18 +1108,18 @@ angular.mock.dump = function(object) {
1030
1108
function MyController($scope, $http) {
1031
1109
var authToken;
1032
1110
1033
- $http.get('/auth.py').success (function(data, status, headers ) {
1034
- authToken = headers('A-Token');
1035
- $scope.user = data;
1111
+ $http.get('/auth.py').then (function(response ) {
1112
+ authToken = response. headers('A-Token');
1113
+ $scope.user = response. data;
1036
1114
});
1037
1115
1038
1116
$scope.saveMessage = function(message) {
1039
1117
var headers = { 'Authorization': authToken };
1040
1118
$scope.status = 'Saving...';
1041
1119
1042
- $http.post('/add-msg.py', message, { headers: headers } ).success (function(response) {
1120
+ $http.post('/add-msg.py', message, { headers: headers } ).then (function(response) {
1043
1121
$scope.status = '';
1044
- }).error (function() {
1122
+ }).catch (function() {
1045
1123
$scope.status = 'Failed...';
1046
1124
});
1047
1125
};
@@ -2093,6 +2171,47 @@ angular.mock.$ControllerDecorator = ['$delegate', function($delegate) {
2093
2171
} ;
2094
2172
} ] ;
2095
2173
2174
+ /**
2175
+ * @ngdoc service
2176
+ * @name $componentController
2177
+ * @description
2178
+ * A service that can be used to create instances of component controllers.
2179
+ * <div class="alert alert-info">
2180
+ * Be aware that the controller will be instantiated and attached to the scope as specified in
2181
+ * the component definition object. That means that you must always provide a `$scope` object
2182
+ * in the `locals` param.
2183
+ * </div>
2184
+ * @param {string } componentName the name of the component whose controller we want to instantiate
2185
+ * @param {Object } locals Injection locals for Controller.
2186
+ * @param {Object= } bindings Properties to add to the controller before invoking the constructor. This is used
2187
+ * to simulate the `bindToController` feature and simplify certain kinds of tests.
2188
+ * @param {string= } ident Override the property name to use when attaching the controller to the scope.
2189
+ * @return {Object } Instance of requested controller.
2190
+ */
2191
+ angular . mock . $ComponentControllerProvider = [ '$compileProvider' , function ( $compileProvider ) {
2192
+ this . $get = [ '$controller' , '$injector' , function ( $controller , $injector ) {
2193
+ return function $componentController ( componentName , locals , bindings , ident ) {
2194
+ // get all directives associated to the component name
2195
+ var directives = $injector . get ( componentName + 'Directive' ) ;
2196
+ // look for those directives that are components
2197
+ var candidateDirectives = directives . filter ( function ( directiveInfo ) {
2198
+ // components have controller, controllerAs and restrict:'E'
2199
+ return directiveInfo . controller && directiveInfo . controllerAs && directiveInfo . restrict === 'E' ;
2200
+ } ) ;
2201
+ // check if valid directives found
2202
+ if ( candidateDirectives . length === 0 ) {
2203
+ throw new Error ( 'No component found' ) ;
2204
+ }
2205
+ if ( candidateDirectives . length > 1 ) {
2206
+ throw new Error ( 'Too many components found' ) ;
2207
+ }
2208
+ // get the info of the component
2209
+ var directiveInfo = candidateDirectives [ 0 ] ;
2210
+ return $controller ( directiveInfo . controller , locals , bindings , ident || directiveInfo . controllerAs ) ;
2211
+ } ;
2212
+ } ] ;
2213
+ } ] ;
2214
+
2096
2215
2097
2216
/**
2098
2217
* @ngdoc module
@@ -2116,7 +2235,8 @@ angular.module('ngMock', ['ng']).provider({
2116
2235
$log : angular . mock . $LogProvider ,
2117
2236
$interval : angular . mock . $IntervalProvider ,
2118
2237
$httpBackend : angular . mock . $HttpBackendProvider ,
2119
- $rootElement : angular . mock . $RootElementProvider
2238
+ $rootElement : angular . mock . $RootElementProvider ,
2239
+ $componentController : angular . mock . $ComponentControllerProvider
2120
2240
} ) . config ( [ '$provide' , function ( $provide ) {
2121
2241
$provide . decorator ( '$timeout' , angular . mock . $TimeoutDecorator ) ;
2122
2242
$provide . decorator ( '$$rAF' , angular . mock . $RAFDecorator ) ;
0 commit comments