|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be |
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | | -import {animate, animateChild, AnimationEvent, AnimationOptions, AUTO_STYLE, group, keyframes, query, state, style, transition, trigger, ɵPRE_STYLE as PRE_STYLE} from '@angular/animations'; |
| 8 | +import {animate, animateChild, AnimationEvent, AnimationMetadata, AnimationOptions, AUTO_STYLE, group, keyframes, query, state, style, transition, trigger, ɵPRE_STYLE as PRE_STYLE} from '@angular/animations'; |
9 | 9 | import {AnimationDriver, ɵAnimationEngine, ɵNoopAnimationDriver as NoopAnimationDriver} from '@angular/animations/browser'; |
10 | 10 | import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing'; |
11 | 11 | import {ChangeDetectorRef, Component, HostBinding, HostListener, Inject, RendererFactory2, ViewChild} from '@angular/core'; |
@@ -4049,6 +4049,97 @@ describe('animation tests', function() { |
4049 | 4049 | }); |
4050 | 4050 | }); |
4051 | 4051 | }); |
| 4052 | + |
| 4053 | + describe('non-animatable css props', () => { |
| 4054 | + function buildAndAnimateSimpleTestComponent(triggerAnimationData: AnimationMetadata[]) { |
| 4055 | + @Component({ |
| 4056 | + selector: 'cmp', |
| 4057 | + template: ` |
| 4058 | + <div *ngIf="exp" [@myAnimation]="exp"> |
| 4059 | + <p *ngIf="exp"></p> |
| 4060 | + </div> |
| 4061 | + `, |
| 4062 | + animations: [trigger('myAnimation', [transition('void => *', triggerAnimationData)])] |
| 4063 | + }) |
| 4064 | + class Cmp { |
| 4065 | + exp: any = false; |
| 4066 | + } |
| 4067 | + |
| 4068 | + TestBed.configureTestingModule({declarations: [Cmp]}); |
| 4069 | + const engine = TestBed.inject(ɵAnimationEngine); |
| 4070 | + const fixture = TestBed.createComponent(Cmp); |
| 4071 | + const cmp = fixture.componentInstance; |
| 4072 | + cmp.exp = true; |
| 4073 | + fixture.detectChanges(); |
| 4074 | + engine.flush(); |
| 4075 | + } |
| 4076 | + |
| 4077 | + it('should show a warning if the animation tries to transition a non-animatable property', () => { |
| 4078 | + const spyWarn = spyOn(console, 'warn'); |
| 4079 | + buildAndAnimateSimpleTestComponent( |
| 4080 | + [style({display: 'block'}), animate(500, style({display: 'inline'}))]); |
| 4081 | + expect(spyWarn).toHaveBeenCalledOnceWith( |
| 4082 | + 'Warning: The animation trigger "myAnimation" is attempting to animate the following' + |
| 4083 | + ' not animatable properties: display' + |
| 4084 | + '\n' + |
| 4085 | + '(to check the list of all animatable properties visit https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties)'); |
| 4086 | + }); |
| 4087 | + |
| 4088 | + it('should not show a warning if the animation tries to transition an animatable property', |
| 4089 | + () => { |
| 4090 | + const spyWarn = spyOn(console, 'warn'); |
| 4091 | + buildAndAnimateSimpleTestComponent( |
| 4092 | + [style({fontSize: 5}), animate(500, style({fontSize: 15}))]); |
| 4093 | + expect(spyWarn).not.toHaveBeenCalled(); |
| 4094 | + }); |
| 4095 | + |
| 4096 | + it('should show a single warning if the animation tries to transition multiple non-animatable properties', |
| 4097 | + () => { |
| 4098 | + const spyWarn = spyOn(console, 'warn'); |
| 4099 | + buildAndAnimateSimpleTestComponent([ |
| 4100 | + style({display: 'block', fontStyle: 'normal'}), |
| 4101 | + animate(500, style({display: 'inline', fontStyle: 'italic'})) |
| 4102 | + ]); |
| 4103 | + expect(spyWarn).toHaveBeenCalledOnceWith( |
| 4104 | + 'Warning: The animation trigger "myAnimation" is attempting to animate the following' + |
| 4105 | + ' not animatable properties: display, fontStyle' + |
| 4106 | + '\n' + |
| 4107 | + '(to check the list of all animatable properties visit https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties)'); |
| 4108 | + }); |
| 4109 | + |
| 4110 | + it('should only warn on non-animatable properties if the animation tries to transition both animate and non-animatable properties', |
| 4111 | + () => { |
| 4112 | + const spyWarn = spyOn(console, 'warn'); |
| 4113 | + buildAndAnimateSimpleTestComponent([ |
| 4114 | + style({'flex-direction': 'column', fontSize: 5}), |
| 4115 | + animate(500, style({'flex-direction': 'row', fontSize: 10})) |
| 4116 | + ]); |
| 4117 | + expect(spyWarn).toHaveBeenCalledOnceWith( |
| 4118 | + 'Warning: The animation trigger "myAnimation" is attempting to animate the following' + |
| 4119 | + ' not animatable properties: flex-direction' + |
| 4120 | + '\n' + |
| 4121 | + '(to check the list of all animatable properties visit https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties)'); |
| 4122 | + }); |
| 4123 | + |
| 4124 | + it('should not show a warning if the animation uses but does not animate a non-animatable property', |
| 4125 | + () => { |
| 4126 | + const spyWarn = spyOn(console, 'warn'); |
| 4127 | + buildAndAnimateSimpleTestComponent([transition('void => *', [style({display: 'block'})])]); |
| 4128 | + expect(spyWarn).not.toHaveBeenCalled(); |
| 4129 | + }); |
| 4130 | + |
| 4131 | + it('should not show a warning if the same non-animatable property is used (with different values) on different elements in the same transition', |
| 4132 | + () => { |
| 4133 | + const spyWarn = spyOn(console, 'warn'); |
| 4134 | + buildAndAnimateSimpleTestComponent([ |
| 4135 | + style({position: 'relative'}), |
| 4136 | + query(':enter', [style({ |
| 4137 | + position: 'absolute', |
| 4138 | + })]), |
| 4139 | + ]); |
| 4140 | + expect(spyWarn).not.toHaveBeenCalled(); |
| 4141 | + }); |
| 4142 | + }); |
4052 | 4143 | }); |
4053 | 4144 | })(); |
4054 | 4145 |
|
|
0 commit comments