@@ -886,6 +886,59 @@ describe('Animation', () => {
886886 expect ( cmp . el . nativeElement . outerHTML ) . toContain ( 'class="slide-in"' ) ;
887887 } ) ) ;
888888
889+ it ( 'should call animation function on entry when animation is specified with no control flow' , fakeAsync ( ( ) => {
890+ @Component ( {
891+ selector : 'test-cmp' ,
892+ styles : styles ,
893+ template : '<div><p (animate.enter)="slideIn($event)">I should slide in</p></div>' ,
894+ encapsulation : ViewEncapsulation . None ,
895+ } )
896+ class TestComponent {
897+ count = signal ( 0 ) ;
898+ slideIn ( event : AnimationCallbackEvent ) {
899+ this . count . update ( ( c ) => ( c += 1 ) ) ;
900+ event . animationComplete ( ) ;
901+ }
902+ }
903+ TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
904+
905+ const fixture = TestBed . createComponent ( TestComponent ) ;
906+ const cmp = fixture . componentInstance ;
907+ fixture . detectChanges ( ) ;
908+ tickAnimationFrames ( 1 ) ;
909+ expect ( cmp . count ( ) ) . toBe ( 1 ) ;
910+ } ) ) ;
911+
912+ it ( 'should call animation function only once on entry when animation is specified with control flow' , fakeAsync ( ( ) => {
913+ @Component ( {
914+ selector : 'test-cmp' ,
915+ styles : styles ,
916+ template :
917+ '<div>@if(show()) {<p (animate.enter)="slideIn($event)">I should slide in</p>}</div>' ,
918+ encapsulation : ViewEncapsulation . None ,
919+ } )
920+ class TestComponent {
921+ count = signal ( 0 ) ;
922+ show = signal ( false ) ;
923+ slideIn ( event : AnimationCallbackEvent ) {
924+ this . count . update ( ( c ) => ( c += 1 ) ) ;
925+ event . animationComplete ( ) ;
926+ }
927+ }
928+ TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
929+
930+ const fixture = TestBed . createComponent ( TestComponent ) ;
931+ const cmp = fixture . componentInstance ;
932+ fixture . detectChanges ( ) ;
933+ tickAnimationFrames ( 1 ) ;
934+ expect ( cmp . count ( ) ) . toBe ( 0 ) ;
935+
936+ cmp . show . update ( ( s ) => ! s ) ;
937+ fixture . detectChanges ( ) ;
938+ tickAnimationFrames ( 1 ) ;
939+ expect ( cmp . count ( ) ) . toBe ( 1 ) ;
940+ } ) ) ;
941+
889942 it ( 'should apply classes on entry when animation is specified' , fakeAsync ( ( ) => {
890943 @Component ( {
891944 selector : 'test-cmp' ,
0 commit comments