|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
| 9 | +import {animate, state, style, transition, trigger} from '@angular/animations'; |
9 | 10 | import {DOCUMENT, isPlatformBrowser, ɵgetDOM as getDOM} from '@angular/common'; |
10 | | -import {APP_INITIALIZER, Compiler, Component, createPlatformFactory, CUSTOM_ELEMENTS_SCHEMA, Directive, ErrorHandler, Inject, InjectionToken, Injector, Input, LOCALE_ID, NgModule, NgModuleRef, OnDestroy, Pipe, PLATFORM_ID, PLATFORM_INITIALIZER, Provider, Sanitizer, StaticProvider, Testability, TestabilityRegistry, Type, VERSION} from '@angular/core'; |
| 11 | +import {ANIMATION_MODULE_TYPE, APP_INITIALIZER, Compiler, Component, createPlatformFactory, CUSTOM_ELEMENTS_SCHEMA, Directive, ErrorHandler, Inject, inject as _inject, InjectionToken, Injector, Input, LOCALE_ID, NgModule, NgModuleRef, OnDestroy, Pipe, PLATFORM_ID, PLATFORM_INITIALIZER, Provider, Sanitizer, StaticProvider, Testability, TestabilityRegistry, Type, VERSION} from '@angular/core'; |
11 | 12 | import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref'; |
12 | 13 | import {Console} from '@angular/core/src/console'; |
13 | 14 | import {ComponentRef} from '@angular/core/src/linker/component_factory'; |
14 | 15 | import {inject, TestBed} from '@angular/core/testing'; |
15 | 16 | import {Log} from '@angular/core/testing/src/testing_internal'; |
16 | 17 | import {BrowserModule} from '@angular/platform-browser'; |
17 | 18 | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; |
| 19 | +import {provideAnimations, provideNoopAnimations} from '@angular/platform-browser/animations'; |
18 | 20 | import {expect} from '@angular/platform-browser/testing/src/matchers'; |
19 | 21 |
|
20 | 22 | import {bootstrapApplication} from '../../src/browser'; |
@@ -314,6 +316,58 @@ function bootstrap( |
314 | 316 | 'make sure it has the `@Component` decorator.'; |
315 | 317 | expect(() => bootstrapApplication(NonAnnotatedClass)).toThrowError(msg); |
316 | 318 | }); |
| 319 | + |
| 320 | + describe('with animations', () => { |
| 321 | + @Component({ |
| 322 | + standalone: true, |
| 323 | + selector: 'hello-app', |
| 324 | + template: ` |
| 325 | + <div |
| 326 | + @myAnimation |
| 327 | + (@myAnimation.start)="onStart($event)">Hello from AnimationCmp!</div>`, |
| 328 | + animations: [trigger( |
| 329 | + 'myAnimation', [transition('void => *', [style({opacity: 1}), animate(5)])])], |
| 330 | + }) |
| 331 | + class AnimationCmp { |
| 332 | + renderer = _inject(ANIMATION_MODULE_TYPE, {optional: true}) ?? 'not found'; |
| 333 | + startEvent?: {}; |
| 334 | + onStart(event: {}) { |
| 335 | + this.startEvent = event; |
| 336 | + } |
| 337 | + } |
| 338 | + |
| 339 | + it('should enable animations when using provideAnimations()', async () => { |
| 340 | + const appRef = await bootstrapApplication(AnimationCmp, { |
| 341 | + providers: [provideAnimations()], |
| 342 | + }); |
| 343 | + const cmp = appRef.components[0].instance; |
| 344 | + |
| 345 | + // Wait until animation is completed. |
| 346 | + await new Promise(resolve => setTimeout(resolve, 10)); |
| 347 | + |
| 348 | + expect(cmp.renderer).toBe('BrowserAnimations'); |
| 349 | + expect(cmp.startEvent.triggerName).toEqual('myAnimation'); |
| 350 | + expect(cmp.startEvent.phaseName).toEqual('start'); |
| 351 | + |
| 352 | + expect(el.innerText).toBe('Hello from AnimationCmp!'); |
| 353 | + }); |
| 354 | + |
| 355 | + it('should use noop animations renderer when using provideNoopAnimations()', async () => { |
| 356 | + const appRef = await bootstrapApplication(AnimationCmp, { |
| 357 | + providers: [provideNoopAnimations()], |
| 358 | + }); |
| 359 | + const cmp = appRef.components[0].instance; |
| 360 | + |
| 361 | + // Wait until animation is completed. |
| 362 | + await new Promise(resolve => setTimeout(resolve, 10)); |
| 363 | + |
| 364 | + expect(cmp.renderer).toBe('NoopAnimations'); |
| 365 | + expect(cmp.startEvent.triggerName).toEqual('myAnimation'); |
| 366 | + expect(cmp.startEvent.phaseName).toEqual('start'); |
| 367 | + |
| 368 | + expect(el.innerText).toBe('Hello from AnimationCmp!'); |
| 369 | + }); |
| 370 | + }); |
317 | 371 | }); |
318 | 372 |
|
319 | 373 | it('should throw if bootstrapped Directive is not a Component', done => { |
|
0 commit comments