@@ -629,7 +629,13 @@ describe('Animation', () => {
629629 cmp . show . set ( true ) ;
630630 fixture . detectChanges ( ) ;
631631 expect ( cmp . show ( ) ) . toBeTruthy ( ) ;
632+ const paragraph = fixture . debugElement . query ( By . css ( 'p' ) ) ;
632633 expect ( cmp . el . nativeElement . outerHTML ) . toContain ( 'class="slide-in"' ) ;
634+ paragraph . nativeElement . dispatchEvent ( new AnimationEvent ( 'animationstart' ) ) ;
635+ paragraph . nativeElement . dispatchEvent (
636+ new AnimationEvent ( 'animationend' , { animationName : 'fade-in' } ) ,
637+ ) ;
638+ expect ( cmp . el . nativeElement . outerHTML ) . not . toContain ( 'class="slide-in fade-in"' ) ;
633639 } ) ;
634640
635641 it ( 'should support string arrays' , ( ) => {
@@ -671,13 +677,74 @@ describe('Animation', () => {
671677 }
672678 TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
673679
680+ const fixture = TestBed . createComponent ( TestComponent ) ;
681+ const cmp = fixture . componentInstance ;
682+ fixture . detectChanges ( ) ;
683+ expect ( cmp . show ( ) ) . toBeFalsy ( ) ;
684+ cmp . show . set ( true ) ;
685+ fixture . detectChanges ( ) ;
686+ const paragraph = fixture . debugElement . query ( By . css ( 'p' ) ) ;
687+ expect ( cmp . show ( ) ) . toBeTruthy ( ) ;
688+ expect ( cmp . el . nativeElement . outerHTML ) . toContain ( 'class="slide-in fade-in"' ) ;
689+ paragraph . nativeElement . dispatchEvent ( new AnimationEvent ( 'animationstart' ) ) ;
690+ paragraph . nativeElement . dispatchEvent (
691+ new AnimationEvent ( 'animationend' , { animationName : 'fade-in' } ) ,
692+ ) ;
693+ expect ( cmp . el . nativeElement . outerHTML ) . not . toContain ( 'class="slide-in fade-in"' ) ;
694+ } ) ;
695+
696+ it ( 'should support multple classes as a single string separated by a space' , ( ) => {
697+ const multiple = `
698+ .slide-in {
699+ animation: slide-in 1ms;
700+ }
701+ .fade-in {
702+ animation: fade-in 2ms;
703+ }
704+ @keyframes slide-in {
705+ from {
706+ transform: translateX(-10px);
707+ }
708+ to {
709+ transform: translateX(0);
710+ }
711+ }
712+ @keyframes fade-in {
713+ from {
714+ opacity: 0;
715+ }
716+ to {
717+ opacity: 1;
718+ }
719+ }
720+ ` ;
721+ @Component ( {
722+ selector : 'test-cmp' ,
723+ styles : multiple ,
724+ template :
725+ '<div>@if (show()) {<p animate.enter="slide-in fade-in" #el>I should slide in</p>}</div>' ,
726+ encapsulation : ViewEncapsulation . None ,
727+ } )
728+ class TestComponent {
729+ show = signal ( false ) ;
730+ @ViewChild ( 'el' , { read : ElementRef } ) el ! : ElementRef < HTMLParagraphElement > ;
731+ }
732+ TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
733+
674734 const fixture = TestBed . createComponent ( TestComponent ) ;
675735 const cmp = fixture . componentInstance ;
676736 fixture . detectChanges ( ) ;
677737 cmp . show . set ( true ) ;
678738 fixture . detectChanges ( ) ;
739+ const paragraph = fixture . debugElement . query ( By . css ( 'p' ) ) ;
679740 expect ( cmp . show ( ) ) . toBeTruthy ( ) ;
680741 expect ( cmp . el . nativeElement . outerHTML ) . toContain ( 'class="slide-in fade-in"' ) ;
742+ fixture . detectChanges ( ) ;
743+ paragraph . nativeElement . dispatchEvent ( new AnimationEvent ( 'animationstart' ) ) ;
744+ paragraph . nativeElement . dispatchEvent (
745+ new AnimationEvent ( 'animationend' , { animationName : 'fade-in' } ) ,
746+ ) ;
747+ expect ( cmp . el . nativeElement . outerHTML ) . not . toContain ( 'class="slide-in fade-in"' ) ;
681748 } ) ;
682749
683750 it ( 'should support multple classes as a single string separated by a space' , ( ) => {
@@ -762,6 +829,12 @@ describe('Animation', () => {
762829 const fixture = TestBed . createComponent ( TestComponent ) ;
763830 fixture . detectChanges ( ) ;
764831 expect ( fixture . debugElement . nativeElement . outerHTML ) . toContain ( 'class="slide-in"' ) ;
832+ const paragraph = fixture . debugElement . query ( By . css ( 'p' ) ) ;
833+ paragraph . nativeElement . dispatchEvent ( new AnimationEvent ( 'animationstart' ) ) ;
834+ paragraph . nativeElement . dispatchEvent (
835+ new AnimationEvent ( 'animationend' , { animationName : 'slide-in' } ) ,
836+ ) ;
837+ expect ( fixture . debugElement . nativeElement . outerHTML ) . toContain ( 'class="slide-in"' ) ;
765838 } ) ;
766839
767840 it ( 'should compose class list when host binding and regular binding' , ( ) => {
@@ -781,6 +854,7 @@ describe('Animation', () => {
781854 styles : styles ,
782855 imports : [ ChildComponent ] ,
783856 template : '<child-cmp [animate.enter]="fadeExp" />' ,
857+ encapsulation : ViewEncapsulation . None ,
784858 } )
785859 class TestComponent {
786860 fadeExp = 'fade-in' ;
@@ -793,6 +867,15 @@ describe('Animation', () => {
793867
794868 expect ( childCmp . nativeElement . className ) . toContain ( 'slide-in' ) ;
795869 expect ( childCmp . nativeElement . className ) . toContain ( 'fade-in' ) ;
870+ childCmp . nativeElement . dispatchEvent ( new AnimationEvent ( 'animationstart' ) ) ;
871+ childCmp . nativeElement . dispatchEvent (
872+ new AnimationEvent ( 'animationend' , { animationName : 'fade-in' } ) ,
873+ ) ;
874+ childCmp . nativeElement . dispatchEvent (
875+ new AnimationEvent ( 'animationend' , { animationName : 'slide-in' } ) ,
876+ ) ;
877+ expect ( childCmp . nativeElement . className ) . not . toContain ( 'slide-in' ) ;
878+ expect ( childCmp . nativeElement . className ) . not . toContain ( 'fade-in' ) ;
796879 } ) ;
797880
798881 it ( 'should compose class list when host binding a string and regular class strings' , ( ) => {
@@ -810,6 +893,7 @@ describe('Animation', () => {
810893 styles : styles ,
811894 imports : [ ChildComponent ] ,
812895 template : '<child-cmp animate.enter="fade-in" />' ,
896+ encapsulation : ViewEncapsulation . None ,
813897 } )
814898 class TestComponent { }
815899 TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
@@ -819,6 +903,15 @@ describe('Animation', () => {
819903 const childCmp = fixture . debugElement . query ( By . css ( 'child-cmp' ) ) ;
820904
821905 expect ( childCmp . nativeElement . className ) . toContain ( 'slide-in fade-in' ) ;
906+ childCmp . nativeElement . dispatchEvent ( new AnimationEvent ( 'animationstart' ) ) ;
907+ childCmp . nativeElement . dispatchEvent (
908+ new AnimationEvent ( 'animationend' , { animationName : 'fade-in' } ) ,
909+ ) ;
910+ childCmp . nativeElement . dispatchEvent (
911+ new AnimationEvent ( 'animationend' , { animationName : 'slide-in' } ) ,
912+ ) ;
913+ fixture . detectChanges ( ) ;
914+ expect ( childCmp . nativeElement . className ) . not . toContain ( 'slide-in fade-in' ) ;
822915 } ) ;
823916 } ) ;
824917} ) ;
0 commit comments