@@ -20,7 +20,7 @@ describe('ngAnimateSwap', function() {
20
20
} ) ) ;
21
21
22
22
23
- it ( 'should render a new container when the expression changes' , inject ( function ( ) {
23
+ it ( 'should render a new container when the expression changes' , function ( ) {
24
24
element = $compile ( '<div><div ng-animate-swap="exp">{{ exp }}</div></div>' ) ( $rootScope ) ;
25
25
$rootScope . $digest ( ) ;
26
26
@@ -40,9 +40,9 @@ describe('ngAnimateSwap', function() {
40
40
expect ( third . textContent ) . toBe ( 'super' ) ;
41
41
expect ( third ) . not . toEqual ( second ) ;
42
42
expect ( second . parentNode ) . toBeFalsy ( ) ;
43
- } ) ) ;
43
+ } ) ;
44
44
45
- it ( 'should render a new container only when the expression property changes' , inject ( function ( ) {
45
+ it ( 'should render a new container only when the expression property changes' , function ( ) {
46
46
element = $compile ( '<div><div ng-animate-swap="exp.prop">{{ exp.value }}</div></div>' ) ( $rootScope ) ;
47
47
$rootScope . exp = {
48
48
prop : 'hello' ,
@@ -66,9 +66,9 @@ describe('ngAnimateSwap', function() {
66
66
var three = element . find ( 'div' ) [ 0 ] ;
67
67
expect ( three . textContent ) . toBe ( 'planet' ) ;
68
68
expect ( three ) . not . toBe ( two ) ;
69
- } ) ) ;
69
+ } ) ;
70
70
71
- it ( 'should watch the expression as a collection' , inject ( function ( ) {
71
+ it ( 'should watch the expression as a collection' , function ( ) {
72
72
element = $compile ( '<div><div ng-animate-swap="exp">{{ exp.a }} {{ exp.b }} {{ exp.c }}</div></div>' ) ( $rootScope ) ;
73
73
$rootScope . exp = {
74
74
a : 1 ,
@@ -99,26 +99,24 @@ describe('ngAnimateSwap', function() {
99
99
var four = element . find ( 'div' ) [ 0 ] ;
100
100
expect ( four . textContent . trim ( ) ) . toBe ( '4' ) ;
101
101
expect ( four ) . not . toEqual ( three ) ;
102
- } ) ) ;
102
+ } ) ;
103
103
104
104
they ( 'should consider $prop as a falsy value' , [ false , undefined , null ] , function ( value ) {
105
- inject ( function ( ) {
106
- element = $compile ( '<div><div ng-animate-swap="value">{{ value }}</div></div>' ) ( $rootScope ) ;
107
- $rootScope . value = true ;
108
- $rootScope . $digest ( ) ;
105
+ element = $compile ( '<div><div ng-animate-swap="value">{{ value }}</div></div>' ) ( $rootScope ) ;
106
+ $rootScope . value = true ;
107
+ $rootScope . $digest ( ) ;
109
108
110
- var one = element . find ( 'div' ) [ 0 ] ;
111
- expect ( one ) . toBeTruthy ( ) ;
109
+ var one = element . find ( 'div' ) [ 0 ] ;
110
+ expect ( one ) . toBeTruthy ( ) ;
112
111
113
- $rootScope . value = value ;
114
- $rootScope . $digest ( ) ;
112
+ $rootScope . value = value ;
113
+ $rootScope . $digest ( ) ;
115
114
116
- var two = element . find ( 'div' ) [ 0 ] ;
117
- expect ( two ) . toBeFalsy ( ) ;
118
- } ) ;
115
+ var two = element . find ( 'div' ) [ 0 ] ;
116
+ expect ( two ) . toBeFalsy ( ) ;
119
117
} ) ;
120
118
121
- it ( 'should consider "0" as a truthy value' , inject ( function ( ) {
119
+ it ( 'should consider "0" as a truthy value' , function ( ) {
122
120
element = $compile ( '<div><div ng-animate-swap="value">{{ value }}</div></div>' ) ( $rootScope ) ;
123
121
$rootScope . $digest ( ) ;
124
122
@@ -130,9 +128,9 @@ describe('ngAnimateSwap', function() {
130
128
131
129
var two = element . find ( 'div' ) [ 0 ] ;
132
130
expect ( two ) . toBeTruthy ( ) ;
133
- } ) ) ;
131
+ } ) ;
134
132
135
- it ( 'should create a new (non-isolate) scope for each inserted clone' , inject ( function ( ) {
133
+ it ( 'should create a new (non-isolate) scope for each inserted clone' , function ( ) {
136
134
var parentScope = $rootScope . $new ( ) ;
137
135
parentScope . foo = 'bar' ;
138
136
@@ -147,9 +145,9 @@ describe('ngAnimateSwap', function() {
147
145
expect ( scopeTwo . foo ) . toBe ( 'bar' ) ;
148
146
149
147
expect ( scopeOne ) . not . toBe ( scopeTwo ) ;
150
- } ) ) ;
148
+ } ) ;
151
149
152
- it ( 'should destroy the previous scope when removing the element' , inject ( function ( ) {
150
+ it ( 'should destroy the previous scope when removing the element' , function ( ) {
153
151
element = $compile ( '<div><div ng-animate-swap="value">{{ value }}</div></div>' ) ( $rootScope ) ;
154
152
155
153
$rootScope . $apply ( 'value = 1' ) ;
@@ -166,9 +164,9 @@ describe('ngAnimateSwap', function() {
166
164
// Removing the old element (without inserting a new one).
167
165
$rootScope . $apply ( 'value = null' ) ;
168
166
expect ( scopeTwo . $$destroyed ) . toBe ( true ) ;
169
- } ) ) ;
167
+ } ) ;
170
168
171
- it ( 'should destroy the previous scope when swapping elements' , inject ( function ( ) {
169
+ it ( 'should destroy the previous scope when swapping elements' , function ( ) {
172
170
element = $compile ( '<div><div ng-animate-swap="value">{{ value }}</div></div>' ) ( $rootScope ) ;
173
171
174
172
$rootScope . $apply ( 'value = 1' ) ;
@@ -177,13 +175,34 @@ describe('ngAnimateSwap', function() {
177
175
178
176
$rootScope . $apply ( 'value = 2' ) ;
179
177
expect ( scopeOne . $$destroyed ) . toBe ( true ) ;
180
- } ) ) ;
178
+ } ) ;
181
179
180
+ it ( 'should work with `ngIf` on the same element' , function ( ) {
181
+ var tmpl = '<div><div ng-animate-swap="exp" ng-if="true">{{ exp }}</div></div>' ;
182
+ element = $compile ( tmpl ) ( $rootScope ) ;
183
+ $rootScope . $digest ( ) ;
182
184
183
- describe ( 'animations' , function ( ) {
184
- it ( 'should trigger a leave animation followed by an enter animation upon swap' ,
185
- inject ( function ( ) {
185
+ var first = element . find ( 'div' ) [ 0 ] ;
186
+ expect ( first ) . toBeFalsy ( ) ;
187
+
188
+ $rootScope . exp = 'yes' ;
189
+ $rootScope . $digest ( ) ;
190
+
191
+ var second = element . find ( 'div' ) [ 0 ] ;
192
+ expect ( second . textContent ) . toBe ( 'yes' ) ;
193
+
194
+ $rootScope . exp = 'super' ;
195
+ $rootScope . $digest ( ) ;
186
196
197
+ var third = element . find ( 'div' ) [ 0 ] ;
198
+ expect ( third . textContent ) . toBe ( 'super' ) ;
199
+ expect ( third ) . not . toEqual ( second ) ;
200
+ expect ( second . parentNode ) . toBeFalsy ( ) ;
201
+ } ) ;
202
+
203
+
204
+ describe ( 'animations' , function ( ) {
205
+ it ( 'should trigger a leave animation followed by an enter animation upon swap' , function ( ) {
187
206
element = $compile ( '<div><div ng-animate-swap="exp">{{ exp }}</div></div>' ) ( $rootScope ) ;
188
207
$rootScope . exp = 1 ;
189
208
$rootScope . $digest ( ) ;
@@ -208,6 +227,6 @@ describe('ngAnimateSwap', function() {
208
227
var forth = $animate . queue . shift ( ) ;
209
228
expect ( forth . event ) . toBe ( 'leave' ) ;
210
229
expect ( $animate . queue . length ) . toBe ( 0 ) ;
211
- } ) ) ;
230
+ } ) ;
212
231
} ) ;
213
232
} ) ;
0 commit comments