|
8 | 8 | import {animate, animateChild, animation, AnimationEvent, AnimationMetadata, AnimationOptions, AUTO_STYLE, group, keyframes, query, sequence, state, style, transition, trigger, useAnimation, ɵ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 | | -import {ChangeDetectorRef, Component, HostBinding, HostListener, Inject, RendererFactory2, ViewChild} from '@angular/core'; |
| 11 | +import {ChangeDetectorRef, Component, HostBinding, HostListener, Inject, RendererFactory2, ViewChild, ViewContainerRef} from '@angular/core'; |
12 | 12 | import {fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing'; |
13 | 13 | import {ɵDomRendererFactory2} from '@angular/platform-browser'; |
14 | 14 | import {ANIMATION_MODULE_TYPE, BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations'; |
@@ -909,6 +909,56 @@ describe('animation tests', function() { |
909 | 909 | ]); |
910 | 910 | })); |
911 | 911 |
|
| 912 | + it('should trigger a leave animation when the inner has ViewContainerRef injected', |
| 913 | + fakeAsync(() => { |
| 914 | + @Component({ |
| 915 | + selector: 'parent-cmp', |
| 916 | + template: ` |
| 917 | + <child-cmp *ngIf="exp"></child-cmp> |
| 918 | + ` |
| 919 | + }) |
| 920 | + class ParentCmp { |
| 921 | + public exp = true; |
| 922 | + } |
| 923 | + |
| 924 | + @Component({ |
| 925 | + selector: 'child-cmp', |
| 926 | + template: '...', |
| 927 | + animations: [trigger( |
| 928 | + 'host', |
| 929 | + [transition(':leave', [style({opacity: 1}), animate(1000, style({opacity: 0}))])])] |
| 930 | + }) |
| 931 | + class ChildCmp { |
| 932 | + @HostBinding('@host') public hostAnimation = true; |
| 933 | + constructor(private vcr: ViewContainerRef) {} |
| 934 | + } |
| 935 | + |
| 936 | + TestBed.configureTestingModule({declarations: [ParentCmp, ChildCmp]}); |
| 937 | + |
| 938 | + const engine = TestBed.inject(ɵAnimationEngine); |
| 939 | + const fixture = TestBed.createComponent(ParentCmp); |
| 940 | + const cmp = fixture.componentInstance; |
| 941 | + fixture.detectChanges(); |
| 942 | + engine.flush(); |
| 943 | + expect(getLog().length).toEqual(0); |
| 944 | + |
| 945 | + cmp.exp = false; |
| 946 | + fixture.detectChanges(); |
| 947 | + expect(fixture.debugElement.nativeElement.children.length).toBe(1); |
| 948 | + |
| 949 | + engine.flush(); |
| 950 | + expect(getLog().length).toEqual(1); |
| 951 | + |
| 952 | + const [player] = getLog(); |
| 953 | + expect(player.keyframes).toEqual([ |
| 954 | + new Map<string, string|number>([['opacity', '1'], ['offset', 0]]), |
| 955 | + new Map<string, string|number>([['opacity', '0'], ['offset', 1]]), |
| 956 | + ]); |
| 957 | + |
| 958 | + player.finish(); |
| 959 | + expect(fixture.debugElement.nativeElement.children.length).toBe(0); |
| 960 | + })); |
| 961 | + |
912 | 962 | it('should trigger a leave animation when the inner components host binding updates', |
913 | 963 | fakeAsync(() => { |
914 | 964 | @Component({ |
|
0 commit comments