test(animations): test to see if triggers get cancelled on removal (#19532)

PR Close #19532
This commit is contained in:
Matias Niemelä 2017-10-04 16:14:17 -07:00 committed by Chuck Jazdzewski
parent d5c9c5f183
commit f12e15e682
1 changed files with 64 additions and 0 deletions

View File

@ -1318,6 +1318,70 @@ export function main() {
expect(count).toEqual(2);
});
it('should cancel all animations on the element when a removal animation is set',
fakeAsync(() => {
const sharedAnimation = [style({opacity: 0}), animate('1s', style({opacity: 1}))];
@Component({
selector: 'ani-cmp',
template: `
<div [@one]="exp1" [@two]="exp2" [@three]="exp3" *ngIf="exp0"></div>
`,
animations: [
trigger(
'one',
[
transition('* => go', sharedAnimation),
transition(
':leave', [style({opacity: 1}), animate('1s', style({opacity: 0}))]),
]),
trigger(
'two',
[
transition('* => go', sharedAnimation),
]),
trigger(
'three',
[
transition('* => go', sharedAnimation),
]),
]
})
class Cmp {
public exp0: any;
public exp1: any;
public exp2: any;
public exp3: any;
}
TestBed.configureTestingModule({declarations: [Cmp]});
const fixture = TestBed.createComponent(Cmp);
const cmp = fixture.componentInstance;
cmp.exp0 = true;
cmp.exp1 = 'go';
cmp.exp2 = 'go';
cmp.exp3 = 'go';
fixture.detectChanges();
flushMicrotasks();
const players = getLog();
resetLog();
expect(players.length).toEqual(3);
let count = 0;
players.forEach(player => { player.onDone(() => count++); });
expect(count).toEqual(0);
cmp.exp0 = false;
fixture.detectChanges();
flushMicrotasks();
expect(count).toEqual(3);
}));
it('should destroy inner animations when a parent node is set for removal', () => {
@Component({
selector: 'ani-cmp',