Skip to content

Commit f2b858d

Browse files
dario-piotrowiczdylhunn
authored andcommitted
refactor(animations): add unit test for leaving animated child (#44489)
add a new unit test to make sure that leaving elements queried via a parent queried via animateChild are correctly removed note: this tests the fix introduced in PR #44357 PR Close #44489
1 parent d4015f7 commit f2b858d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

packages/core/test/animation/animation_query_integration_spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,51 @@ describe('animation query tests', function() {
33483348
expect(pp.element.classList.contains('container')).toBeTruthy();
33493349
expect(pcp.element.classList.contains('item')).toBeTruthy();
33503350
});
3351+
3352+
it('should correctly remove a leaving element queried/animated by a parent queried via animateChild',
3353+
fakeAsync(() => {
3354+
@Component({
3355+
selector: 'cmp',
3356+
template: `
3357+
<div class="grand-parent" [@grandParentAnimation]="childPresent">
3358+
<div class="parent" [@parentAnimation]="childPresent">
3359+
<div *ngIf="childPresent" class="child"></div>
3360+
</div>
3361+
</div>
3362+
`,
3363+
animations: [
3364+
trigger(
3365+
'grandParentAnimation',
3366+
[transition('true <=> false', query('@parentAnimation', animateChild()))]),
3367+
trigger(
3368+
'parentAnimation',
3369+
[transition(
3370+
'true => false', query(':leave.child', animate('.2s', style({opacity: 0}))))])
3371+
]
3372+
})
3373+
class Cmp {
3374+
public childPresent = true;
3375+
}
3376+
3377+
TestBed.configureTestingModule({declarations: [Cmp]});
3378+
3379+
const engine = TestBed.inject(ɵAnimationEngine);
3380+
const fixture = TestBed.createComponent(Cmp);
3381+
const cmp = fixture.componentInstance;
3382+
fixture.detectChanges();
3383+
3384+
let children = fixture.debugElement.nativeElement.querySelectorAll('.child');
3385+
expect(children.length).toEqual(1);
3386+
3387+
cmp.childPresent = false;
3388+
fixture.detectChanges();
3389+
flushMicrotasks();
3390+
3391+
engine.players.forEach(player => player.finish());
3392+
3393+
children = fixture.debugElement.nativeElement.querySelectorAll('.child');
3394+
expect(children.length).toEqual(0);
3395+
}));
33513396
});
33523397

33533398
describe('animation control flags', () => {

0 commit comments

Comments
 (0)