11/**
2- *
32 * AngularJS-Material-Mocks
43 *
54 * Developers interested in running their own custom unit tests WITH angular-material.js loaded...
109 * - Forces $mdAria.expectWithText() to be synchronous
1110 * - Mocks $$rAF.throttle()
1211 * - Captures flush exceptions from $$rAF
13- *
1412 */
13+ // eslint-disable-next-line no-shadow-restricted-names
1514( function ( window , angular , undefined ) {
1615
17- 'use strict' ;
16+ 'use strict' ;
1817
1918 // Allow our code to know when they are running inside of a test so they can expose extra services
2019 // that should NOT be exposed to the public but that should be tested.
2120 //
2221 // As an example, see input.js which exposes some animation-related methods.
2322 window . _mdMocksIncluded = true ;
2423
25- /**
26- * @ngdoc module
27- * @name ngMaterial-mock
28- * @packageName angular-material-mocks
29- *
30- * @description
31- *
32- * The `ngMaterial-mock` module provides support
33- *
34- */
35- angular . module ( 'ngMaterial-mock' , [
36- 'ngMock' ,
37- 'ngAnimateMock' ,
38- 'material.core'
39- ] )
40- . config ( [ '$provide' , function ( $provide ) {
41-
42- $provide . factory ( '$material' , [ '$animate' , '$timeout' , function ( $animate , $timeout ) {
43- return {
44- flushOutstandingAnimations : function ( ) {
45- // this code is placed in a try-catch statement
46- // since 1.3 and 1.4 handle their animations differently
47- // and there may be situations where follow-up animations
48- // are run in one version and not the other
49- try { $animate . flush ( ) ; } catch ( e ) { }
50- } ,
51- flushInterimElement : function ( ) {
52- this . flushOutstandingAnimations ( ) ;
53- $timeout . flush ( ) ;
54- this . flushOutstandingAnimations ( ) ;
55- $timeout . flush ( ) ;
56- this . flushOutstandingAnimations ( ) ;
57- $timeout . flush ( ) ;
24+ /**
25+ * @ngdoc module
26+ * @name ngMaterial-mock
27+ * @packageName angular-material-mocks
28+ *
29+ * @description
30+ * The `ngMaterial-mock` module provides support
31+ */
32+ angular . module ( 'ngMaterial-mock' , [ 'ngMock' , 'ngAnimateMock' , 'material.core' ] ) . config ( [
33+ '$provide' ,
34+ function ( $provide ) {
35+ $provide . factory ( '$material' , [
36+ '$animate' , '$timeout' ,
37+ function ( $animate , $timeout ) {
38+ return {
39+ flushOutstandingAnimations : function ( ) {
40+ // this code is placed in a try-catch statement
41+ // since 1.3 and 1.4 handle their animations differently
42+ // and there may be situations where follow-up animations
43+ // are run in one version and not the other
44+ try {
45+ $animate . flush ( ) ;
46+ // eslint-disable-next-line no-empty
47+ } catch ( e ) { }
48+ } ,
49+ flushInterimElement : function ( ) {
50+ this . flushOutstandingAnimations ( ) ;
51+ $timeout . flush ( ) ;
52+ this . flushOutstandingAnimations ( ) ;
53+ $timeout . flush ( ) ;
54+ this . flushOutstandingAnimations ( ) ;
55+ $timeout . flush ( ) ;
56+ }
57+ } ;
5858 }
59- } ;
60- } ] ) ;
61-
62- /**
63- * AngularJS Material dynamically generates Style tags
64- * based on themes and palettes; for each ng-app.
65- *
66- * For testing, we want to disable generation and
67- * <style> DOM injections. So we clear the huge THEME
68- * styles while testing...
69- */
70- $provide . constant ( '$MD_THEME_CSS' , '/**/' ) ;
71-
72- /**
73- * Add throttle() and wrap .flush() to catch `no callbacks present`
74- * errors
75- */
76- $provide . decorator ( '$$rAF' , function throttleInjector ( $delegate ) {
77-
78- $delegate . throttle = function ( cb ) {
79- return function ( ) {
80- cb . apply ( this , arguments ) ;
59+ ] ) ;
60+
61+ /**
62+ * AngularJS Material dynamically generates Style tags
63+ * based on themes and palettes; for each ng-app.
64+ *
65+ * For testing, we want to disable generation and
66+ * <style> DOM injections. So we clear the huge THEME
67+ * styles while testing...
68+ */
69+ $provide . constant ( '$MD_THEME_CSS' , '/**/' ) ;
70+
71+ /**
72+ * Add throttle() and wrap .flush() to catch `no callbacks present`
73+ * errors
74+ */
75+ $provide . decorator ( '$$rAF' , function throttleInjector ( $delegate ) {
76+ $delegate . throttle = function ( cb ) {
77+ return function ( ) {
78+ cb . apply ( this , arguments ) ;
79+ } ;
8180 } ;
82- } ;
83-
84- var ngFlush = $delegate . flush ;
85- $delegate . flush = function ( ) {
86- try { ngFlush ( ) ; }
87- catch ( e ) { ; }
88- } ;
8981
90- return $delegate ;
91- } ) ;
92-
93- /**
94- * Capture $timeout.flush() errors: "No deferred tasks to be flushed"
95- * errors
96- */
97- $provide . decorator ( '$timeout' , function throttleInjector ( $delegate ) {
98-
99- var ngFlush = $delegate . flush ;
100- $delegate . flush = function ( ) {
101- var args = Array . prototype . slice . call ( arguments ) ;
102- try { ngFlush . apply ( $delegate , args ) ; }
103- catch ( e ) { }
104- } ;
82+ const ngFlush = $delegate . flush ;
83+ $delegate . flush = function ( ) {
84+ try {
85+ ngFlush ( ) ;
86+ // eslint-disable-next-line no-empty
87+ } catch ( e ) { }
88+ } ;
10589
106- return $delegate ;
107- } ) ;
90+ return $delegate ;
91+ } ) ;
92+
93+ /**
94+ * Capture $timeout.flush() errors: "No deferred tasks to be flushed"
95+ * errors
96+ */
97+ $provide . decorator ( '$timeout' , function throttleInjector ( $delegate ) {
98+ const ngFlush = $delegate . flush ;
99+ $delegate . flush = function ( ) {
100+ const args = Array . prototype . slice . call ( arguments ) ;
101+ try {
102+ ngFlush . apply ( $delegate , args ) ;
103+ // eslint-disable-next-line no-empty
104+ } catch ( e ) { }
105+ } ;
108106
109- } ] ) ;
107+ return $delegate ;
108+ } ) ;
109+ }
110+ ] ) ;
110111
111112 /**
112113 * Stylesheet Mocks used by `animateCss.spec.js`
@@ -115,24 +116,23 @@ angular.module('ngMaterial-mock', [
115116 doc = doc ? doc [ 0 ] : window . document ;
116117 wind = wind || window ;
117118
118- var node = doc . createElement ( 'style' ) ;
119- var head = doc . getElementsByTagName ( 'head' ) [ 0 ] ;
119+ const node = doc . createElement ( 'style' ) ;
120+ const head = doc . getElementsByTagName ( 'head' ) [ 0 ] ;
120121 head . appendChild ( node ) ;
121122
122- var ss = doc . styleSheets [ doc . styleSheets . length - 1 ] ;
123+ const ss = doc . styleSheets [ doc . styleSheets . length - 1 ] ;
123124
124125 return {
125126 addRule : function ( selector , styles ) {
126127 styles = addVendorPrefix ( styles ) ;
127128
128129 try {
129130 ss . insertRule ( selector + '{ ' + styles + '}' , 0 ) ;
130- }
131- catch ( e ) {
131+ } catch ( e ) {
132132 try {
133133 ss . addRule ( selector , styles ) ;
134- }
135- catch ( e2 ) { }
134+ // eslint-disable-next-line no-empty
135+ } catch ( e2 ) { }
136136 }
137137 } ,
138138
@@ -150,37 +150,33 @@ angular.module('ngMaterial-mock', [
150150 * '-webkit-transition:0.5s linear all; transition:0.5s linear all; font-size:100px;'
151151 */
152152 function addVendorPrefix ( styles ) {
153- var cache = { } ;
153+ const cache = { } ;
154154
155155 // Decompose into cache registry
156- styles
157- . match ( / ( [ \- A - Z a - z ] * ) \w \: \w * ( [ A - Z a - z 0 - 9 \. \- \s ] * ) / gi)
158- . forEach ( function ( style ) {
159- var pair = style . split ( ":" ) ;
160- var key = pair [ 0 ] ;
161-
162- switch ( key ) {
163- case 'transition' :
164- case 'transform' :
165- case 'animation' :
166- case 'transition-duration' :
167- case 'animation-duration' :
168- cache [ key ] = cache [ '-webkit-' + key ] = pair [ 1 ] ;
169- break ;
170- default :
171- cache [ key ] = pair [ 1 ] ;
172- }
173- } ) ;
174-
175- // Recompose full style object (as string)
176- styles = "" ;
177- angular . forEach ( cache , function ( value , key ) {
178- styles = styles + key + ":" + value + "; " ;
179- } ) ;
180-
181- return styles ;
182- }
156+ styles . match ( / ( [ - A - Z a - z ] * ) \w : \w * ( [ A - Z a - z 0 - 9 . \- \s ] * ) / gi) . forEach ( function ( style ) {
157+ const pair = style . split ( ':' ) ;
158+ const key = pair [ 0 ] ;
159+
160+ switch ( key ) {
161+ case 'transition' :
162+ case 'transform' :
163+ case 'animation' :
164+ case 'transition-duration' :
165+ case 'animation-duration' :
166+ cache [ key ] = cache [ '-webkit-' + key ] = pair [ 1 ] ;
167+ break ;
168+ default :
169+ cache [ key ] = pair [ 1 ] ;
170+ }
171+ } ) ;
183172
184- } ;
173+ // Recompose full style object (as string)
174+ styles = '' ;
175+ angular . forEach ( cache , function ( value , key ) {
176+ styles = styles + key + ':' + value + '; ' ;
177+ } ) ;
185178
179+ return styles ;
180+ }
181+ } ;
186182} ) ( window , window . angular ) ;
0 commit comments