@@ -629,7 +629,13 @@ describe('Animation', () => {
629
629
cmp . show . set ( true ) ;
630
630
fixture . detectChanges ( ) ;
631
631
expect ( cmp . show ( ) ) . toBeTruthy ( ) ;
632
+ const paragraph = fixture . debugElement . query ( By . css ( 'p' ) ) ;
632
633
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"' ) ;
633
639
} ) ;
634
640
635
641
it ( 'should support string arrays' , ( ) => {
@@ -671,13 +677,74 @@ describe('Animation', () => {
671
677
}
672
678
TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
673
679
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
+
674
734
const fixture = TestBed . createComponent ( TestComponent ) ;
675
735
const cmp = fixture . componentInstance ;
676
736
fixture . detectChanges ( ) ;
677
737
cmp . show . set ( true ) ;
678
738
fixture . detectChanges ( ) ;
739
+ const paragraph = fixture . debugElement . query ( By . css ( 'p' ) ) ;
679
740
expect ( cmp . show ( ) ) . toBeTruthy ( ) ;
680
741
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"' ) ;
681
748
} ) ;
682
749
683
750
it ( 'should support multple classes as a single string separated by a space' , ( ) => {
@@ -762,6 +829,12 @@ describe('Animation', () => {
762
829
const fixture = TestBed . createComponent ( TestComponent ) ;
763
830
fixture . detectChanges ( ) ;
764
831
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"' ) ;
765
838
} ) ;
766
839
767
840
it ( 'should compose class list when host binding and regular binding' , ( ) => {
@@ -781,6 +854,7 @@ describe('Animation', () => {
781
854
styles : styles ,
782
855
imports : [ ChildComponent ] ,
783
856
template : '<child-cmp [animate.enter]="fadeExp" />' ,
857
+ encapsulation : ViewEncapsulation . None ,
784
858
} )
785
859
class TestComponent {
786
860
fadeExp = 'fade-in' ;
@@ -793,6 +867,15 @@ describe('Animation', () => {
793
867
794
868
expect ( childCmp . nativeElement . className ) . toContain ( 'slide-in' ) ;
795
869
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' ) ;
796
879
} ) ;
797
880
798
881
it ( 'should compose class list when host binding a string and regular class strings' , ( ) => {
@@ -810,6 +893,7 @@ describe('Animation', () => {
810
893
styles : styles ,
811
894
imports : [ ChildComponent ] ,
812
895
template : '<child-cmp animate.enter="fade-in" />' ,
896
+ encapsulation : ViewEncapsulation . None ,
813
897
} )
814
898
class TestComponent { }
815
899
TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
@@ -819,6 +903,15 @@ describe('Animation', () => {
819
903
const childCmp = fixture . debugElement . query ( By . css ( 'child-cmp' ) ) ;
820
904
821
905
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' ) ;
822
915
} ) ;
823
916
} ) ;
824
917
} ) ;
0 commit comments