5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { AUTO_STYLE , AnimationEvent , AnimationOptions , animate , animateChild , group , keyframes , query , state , style , transition , trigger , ɵPRE_STYLE as PRE_STYLE } from '@angular/animations' ;
9
- import { AnimationDriver , ɵAnimationEngine , ɵNoopAnimationDriver } from '@angular/animations/browser' ;
8
+ import { AUTO_STYLE , AnimationEvent , AnimationOptions , AnimationPlayer , NoopAnimationPlayer , animate , animateChild , group , keyframes , query , state , style , transition , trigger , ɵPRE_STYLE as PRE_STYLE } from '@angular/animations' ;
9
+ import { AnimationDriver , ɵAnimationEngine , ɵNoopAnimationDriver as NoopAnimationDriver } from '@angular/animations/browser' ;
10
10
import { MockAnimationDriver , MockAnimationPlayer } from '@angular/animations/browser/testing' ;
11
11
import { ChangeDetectorRef , Component , HostBinding , HostListener , RendererFactory2 , ViewChild } from '@angular/core' ;
12
12
import { ɵDomRendererFactory2 } from '@angular/platform-browser' ;
@@ -112,6 +112,50 @@ const DEFAULT_COMPONENT_ID = '1';
112
112
flushMicrotasks ( ) ;
113
113
expect ( cmp . log ) . toEqual ( [ 'start' , 'done' ] ) ;
114
114
} ) ) ;
115
+
116
+ it ( 'should emit the correct totalTime value for a noop-animation' , fakeAsync ( ( ) => {
117
+ @Component ( {
118
+ selector : 'cmp' ,
119
+ template : `
120
+ <div [@myAnimation]="exp" (@myAnimation.start)="cb($event)" (@myAnimation.done)="cb($event)"></div>
121
+ ` ,
122
+ animations : [
123
+ trigger (
124
+ 'myAnimation' ,
125
+ [
126
+ transition (
127
+ '* => go' ,
128
+ [
129
+ animate ( '1s' , style ( { opacity : 0 } ) ) ,
130
+ ] ) ,
131
+ ] ) ,
132
+ ]
133
+ } )
134
+ class Cmp {
135
+ exp : any = false ;
136
+ log : AnimationEvent [ ] = [ ] ;
137
+ cb ( event : AnimationEvent ) { this . log . push ( event ) ; }
138
+ }
139
+
140
+ TestBed . configureTestingModule ( {
141
+ declarations : [ Cmp ] ,
142
+ providers : [
143
+ { provide : AnimationDriver , useClass : NoopAnimationDriver } ,
144
+ ] ,
145
+ } ) ;
146
+
147
+ const fixture = TestBed . createComponent ( Cmp ) ;
148
+ const cmp = fixture . componentInstance ;
149
+ cmp . exp = 'go' ;
150
+ fixture . detectChanges ( ) ;
151
+ expect ( cmp . log ) . toEqual ( [ ] ) ;
152
+
153
+ flushMicrotasks ( ) ;
154
+ expect ( cmp . log . length ) . toEqual ( 2 ) ;
155
+ const [ start , end ] = cmp . log ;
156
+ expect ( start . totalTime ) . toEqual ( 1000 ) ;
157
+ expect ( end . totalTime ) . toEqual ( 1000 ) ;
158
+ } ) ) ;
115
159
} ) ;
116
160
117
161
describe ( 'component fixture integration' , ( ) => {
@@ -166,7 +210,7 @@ const DEFAULT_COMPONENT_ID = '1';
166
210
}
167
211
168
212
TestBed . configureTestingModule ( {
169
- providers : [ { provide : AnimationDriver , useClass : ɵNoopAnimationDriver } ] ,
213
+ providers : [ { provide : AnimationDriver , useClass : NoopAnimationDriver } ] ,
170
214
declarations : [ Cmp ]
171
215
} ) ;
172
216
@@ -2461,7 +2505,7 @@ const DEFAULT_COMPONENT_ID = '1';
2461
2505
}
2462
2506
2463
2507
TestBed . configureTestingModule ( {
2464
- providers : [ { provide : AnimationDriver , useClass : ɵNoopAnimationDriver } ] ,
2508
+ providers : [ { provide : AnimationDriver , useClass : NoopAnimationDriver } ] ,
2465
2509
declarations : [ Cmp ]
2466
2510
} ) ;
2467
2511
@@ -2500,7 +2544,7 @@ const DEFAULT_COMPONENT_ID = '1';
2500
2544
}
2501
2545
2502
2546
TestBed . configureTestingModule ( {
2503
- providers : [ { provide : AnimationDriver , useClass : ɵNoopAnimationDriver } ] ,
2547
+ providers : [ { provide : AnimationDriver , useClass : NoopAnimationDriver } ] ,
2504
2548
declarations : [ Cmp ]
2505
2549
} ) ;
2506
2550
@@ -2971,8 +3015,8 @@ const DEFAULT_COMPONENT_ID = '1';
2971
3015
class Cmp {
2972
3016
disableExp = false ;
2973
3017
exp = '' ;
2974
- startEvent : any ;
2975
- doneEvent : any ;
3018
+ startEvent : AnimationEvent ;
3019
+ doneEvent : AnimationEvent ;
2976
3020
}
2977
3021
2978
3022
TestBed . configureTestingModule ( { declarations : [ Cmp ] } ) ;
@@ -2988,14 +3032,17 @@ const DEFAULT_COMPONENT_ID = '1';
2988
3032
cmp . exp = '1' ;
2989
3033
fixture . detectChanges ( ) ;
2990
3034
flushMicrotasks ( ) ;
2991
- expect ( cmp . startEvent . totalTime ) . toEqual ( 0 ) ;
2992
- expect ( cmp . doneEvent . totalTime ) . toEqual ( 0 ) ;
3035
+ expect ( cmp . startEvent . totalTime ) . toEqual ( 9876 ) ;
3036
+ expect ( cmp . startEvent . disabled ) . toBeTruthy ( ) ;
3037
+ expect ( cmp . doneEvent . totalTime ) . toEqual ( 9876 ) ;
3038
+ expect ( cmp . doneEvent . disabled ) . toBeTruthy ( ) ;
2993
3039
2994
3040
cmp . exp = '2' ;
2995
3041
cmp . disableExp = false ;
2996
3042
fixture . detectChanges ( ) ;
2997
3043
flushMicrotasks ( ) ;
2998
3044
expect ( cmp . startEvent . totalTime ) . toEqual ( 9876 ) ;
3045
+ expect ( cmp . startEvent . disabled ) . toBeFalsy ( ) ;
2999
3046
// the done event isn't fired because it's an actual animation
3000
3047
} ) ) ;
3001
3048
@@ -3428,7 +3475,7 @@ const DEFAULT_COMPONENT_ID = '1';
3428
3475
} ) ;
3429
3476
} ) ;
3430
3477
} ) ;
3431
- } ) ;
3478
+ } ) ( ) ;
3432
3479
3433
3480
function assertHasParent ( element : any , yes : boolean ) {
3434
3481
const parent = getDOM ( ) . parentElement ( element ) ;
0 commit comments