@@ -23,8 +23,8 @@ import {fakeAsync, TestBed, tick} from '@angular/core/testing';
2323import { By } from '@angular/platform-browser' ;
2424import { isNode } from '@angular/private/testing' ;
2525import { tickAnimationFrames } from '../animation_utils/tick_animation_frames' ;
26- import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
2726import { BrowserTestingModule , platformBrowserTesting } from '@angular/platform-browser/testing' ;
27+ import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
2828
2929@NgModule ( {
3030 providers : [ provideZonelessChangeDetection ( ) ] ,
@@ -37,11 +37,19 @@ describe('Animation', () => {
3737 return ;
3838 }
3939
40- beforeAll ( ( ) => {
40+ beforeEach ( ( ) => {
4141 TestBed . resetTestEnvironment ( ) ;
4242 TestBed . initTestEnvironment ( [ BrowserTestingModule , TestModule ] , platformBrowserTesting ( ) ) ;
4343 } ) ;
4444
45+ afterEach ( ( ) => {
46+ TestBed . resetTestEnvironment ( ) ;
47+ TestBed . initTestEnvironment (
48+ [ BrowserTestingModule , NoopAnimationsModule , TestModule ] ,
49+ platformBrowserTesting ( ) ,
50+ ) ;
51+ } ) ;
52+
4553 afterAll ( ( ) => {
4654 TestBed . resetTestEnvironment ( ) ;
4755 TestBed . initTestEnvironment (
@@ -709,6 +717,70 @@ describe('Animation', () => {
709717 expect ( fixture . nativeElement . outerHTML ) . not . toContain ( 'slide-out fade ' ) ;
710718 expect ( fixture . debugElement . query ( By . css ( 'child-cmp' ) ) ) . toBeNull ( ) ;
711719 } ) ) ;
720+
721+ describe ( 'legacy animations compatibility' , ( ) => {
722+ beforeAll ( ( ) => {
723+ TestBed . resetTestEnvironment ( ) ;
724+ TestBed . initTestEnvironment (
725+ [ BrowserTestingModule , NoopAnimationsModule , TestModule ] ,
726+ platformBrowserTesting ( ) ,
727+ ) ;
728+ } ) ;
729+
730+ const styles = `
731+ .fade {
732+ animation: fade-out 1ms;
733+ }
734+ @keyframes fade-out {
735+ from {
736+ opacity: 1;
737+ }
738+ to {
739+ opacity: 0;
740+ }
741+ }
742+ ` ;
743+
744+ it ( 'should have the same exact timing when AnimationsModule is present' , fakeAsync ( ( ) => {
745+ const logSpy = jasmine . createSpy ( 'logSpy' ) ;
746+ @Component ( {
747+ selector : 'test-cmp' ,
748+ styles : styles ,
749+ template :
750+ '<div>@if (show()) {<p animate.leave="fade" (animationend)="logMe($event)">I should fade</p>}</div>' ,
751+ encapsulation : ViewEncapsulation . None ,
752+ } )
753+ class TestComponent {
754+ show = signal ( true ) ;
755+
756+ logMe ( event : AnimationEvent ) {
757+ logSpy ( ) ;
758+ }
759+ }
760+
761+ TestBed . configureTestingModule ( { animationsEnabled : true } ) ;
762+
763+ const fixture = TestBed . createComponent ( TestComponent ) ;
764+ const cmp = fixture . componentInstance ;
765+ fixture . detectChanges ( ) ;
766+ const paragragh = fixture . debugElement . query ( By . css ( 'p' ) ) ;
767+
768+ expect ( fixture . nativeElement . outerHTML ) . not . toContain ( 'class="fade"' ) ;
769+ cmp . show . set ( false ) ;
770+ fixture . detectChanges ( ) ;
771+ tickAnimationFrames ( 1 ) ;
772+ expect ( cmp . show ( ) ) . toBeFalsy ( ) ;
773+ fixture . detectChanges ( ) ;
774+ expect ( fixture . nativeElement . outerHTML ) . toContain ( 'class="fade"' ) ;
775+ fixture . detectChanges ( ) ;
776+ paragragh . nativeElement . dispatchEvent (
777+ new AnimationEvent ( 'animationend' , { animationName : 'fade-out' } ) ,
778+ ) ;
779+ tick ( ) ;
780+ expect ( fixture . nativeElement . outerHTML ) . not . toContain ( 'class="fade"' ) ;
781+ expect ( logSpy ) . toHaveBeenCalled ( ) ;
782+ } ) ) ;
783+ } ) ;
712784 } ) ;
713785
714786 describe ( 'animate.enter' , ( ) => {
0 commit comments