1
1
describe ( 'md-input-container animations' , function ( ) {
2
2
var $rootScope , $compile , $animate , $animateCss ,
3
3
el , pageScope , invalidAnimation , messagesAnimation , messageAnimation ,
4
- cssTransitionsDisabled = false ;
4
+ cssTransitionsDisabled = false , lastAnimateCall ;
5
5
6
6
// Load our modules
7
7
beforeEach ( module ( 'ngAnimate' , 'ngMessages' , 'material.components.input' ) ) ;
@@ -44,7 +44,7 @@ describe('md-input-container animations', function() {
44
44
45
45
expectError ( getError ( ) , 'pattern' ) ;
46
46
expect ( container ) . not . toHaveClass ( 'md-input-invalid' ) ;
47
- expect ( lastAnimateCall ( ) ) . toEqual ( { element : getError ( ) , options : { } } ) ;
47
+ expect ( lastAnimateCall ) . toEqual ( { element : getError ( ) , options : { } } ) ;
48
48
49
49
/*
50
50
* 2. Blur the input, which adds the md-input-invalid class
@@ -58,9 +58,9 @@ describe('md-input-container animations', function() {
58
58
59
59
expectError ( getError ( ) , 'pattern' ) ;
60
60
expect ( container ) . toHaveClass ( 'md-input-invalid' ) ;
61
- expect ( lastAnimateCall ( ) . element ) . toEqual ( getError ( ) ) ;
62
- expect ( lastAnimateCall ( ) . options . event ) . toEqual ( 'enter' ) ;
63
- expect ( lastAnimateCall ( ) . options . to ) . toEqual ( { "opacity" : 1 , "margin-top" : "0" } ) ;
61
+ expect ( lastAnimateCall . element ) . toEqual ( getError ( ) ) ;
62
+ expect ( lastAnimateCall . options . event ) . toEqual ( 'enter' ) ;
63
+ expect ( lastAnimateCall . options . to ) . toEqual ( { "opacity" : 1 , "margin-top" : "0" } ) ;
64
64
65
65
/*
66
66
* 3. Clear the field
@@ -74,9 +74,9 @@ describe('md-input-container animations', function() {
74
74
messageAnimation . leave ( patternError ) . start ( ) . done ( angular . noop ) ;
75
75
$animate . flush ( ) ;
76
76
77
- expect ( lastAnimateCall ( ) . element ) . toEqual ( patternError ) ;
78
- expect ( lastAnimateCall ( ) . options . event ) . toEqual ( 'leave' ) ;
79
- expect ( parseInt ( lastAnimateCall ( ) . options . to [ "margin-top" ] ) ) . toBeLessThan ( 0 ) ;
77
+ expect ( lastAnimateCall . element ) . toEqual ( patternError ) ;
78
+ expect ( lastAnimateCall . options . event ) . toEqual ( 'leave' ) ;
79
+ expect ( parseInt ( lastAnimateCall . options . to [ "margin-top" ] ) ) . toBeLessThan ( 0 ) ;
80
80
81
81
setFoo ( '' ) ;
82
82
expectError ( getError ( ) , 'required' ) ;
@@ -85,9 +85,9 @@ describe('md-input-container animations', function() {
85
85
$animate . flush ( ) ;
86
86
87
87
expect ( container ) . toHaveClass ( 'md-input-invalid' ) ;
88
- expect ( lastAnimateCall ( ) . element ) . toEqual ( getError ( ) ) ;
89
- expect ( lastAnimateCall ( ) . options . event ) . toEqual ( 'enter' ) ;
90
- expect ( lastAnimateCall ( ) . options . to ) . toEqual ( { "opacity" : 1 , "margin-top" : "0" } ) ;
88
+ expect ( lastAnimateCall . element ) . toEqual ( getError ( ) ) ;
89
+ expect ( lastAnimateCall . options . event ) . toEqual ( 'enter' ) ;
90
+ expect ( lastAnimateCall . options . to ) . toEqual ( { "opacity" : 1 , "margin-top" : "0" } ) ;
91
91
} ) ;
92
92
93
93
/*
@@ -103,13 +103,6 @@ describe('md-input-container animations', function() {
103
103
return el ;
104
104
}
105
105
106
- function lastAnimateCall ( ) {
107
- return {
108
- element : $animateCss . calls . mostRecent ( ) . args [ 0 ] ,
109
- options : $animateCss . calls . mostRecent ( ) . args [ 1 ]
110
- }
111
- }
112
-
113
106
function setFoo ( value ) {
114
107
pageScope . foo = value ;
115
108
pageScope . $digest ( ) ;
@@ -132,6 +125,16 @@ describe('md-input-container animations', function() {
132
125
module ( function ( $provide ) {
133
126
$provide . decorator ( '$animateCss' , function ( $delegate ) {
134
127
return jasmine . createSpy ( '$animateCss' ) . and . callFake ( function ( element , options ) {
128
+
129
+ // Store the last call to $animateCss
130
+ //
131
+ // NOTE: We handle this manually because the actual code modifies the options
132
+ // and can make the tests fail if it executes before the expect() fires
133
+ lastAnimateCall = {
134
+ element : element ,
135
+ options : angular . copy ( options )
136
+ } ;
137
+
135
138
// Make sure any transitions happen immediately; NOTE: this is REQUIRED for the above
136
139
// tests to pass without using window.setTimeout to wait for the animations
137
140
if ( cssTransitionsDisabled ) {
0 commit comments