|
6 | 6 | ViewContainerRef,
|
7 | 7 | ViewEncapsulation,
|
8 | 8 | } from '@angular/core';
|
9 |
| -import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing'; |
| 9 | +import {waitForAsync, ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/testing'; |
10 | 10 | import {PortalModule, CdkPortalOutlet, TemplatePortal} from '@angular/cdk/portal';
|
11 | 11 | import {A11yModule, FocusTrap, CdkTrapFocus} from '../index';
|
12 | 12 | import {By} from '@angular/platform-browser';
|
@@ -89,10 +89,11 @@ describe('FocusTrap', () => {
|
89 | 89 | describe('with bindings', () => {
|
90 | 90 | let fixture: ComponentFixture<FocusTrapWithBindings>;
|
91 | 91 |
|
92 |
| - beforeEach(() => { |
| 92 | + beforeEach(fakeAsync(() => { |
93 | 93 | fixture = TestBed.createComponent(FocusTrapWithBindings);
|
94 | 94 | fixture.detectChanges();
|
95 |
| - }); |
| 95 | + tick(); |
| 96 | + })); |
96 | 97 |
|
97 | 98 | it('should clean up its anchor sibling elements on destroy', () => {
|
98 | 99 | const rootElement = fixture.debugElement.nativeElement as HTMLElement;
|
@@ -296,26 +297,28 @@ describe('FocusTrap', () => {
|
296 | 297 |
|
297 | 298 | });
|
298 | 299 |
|
299 |
| - it('should put anchors inside the outlet when set at the root of a template portal', () => { |
300 |
| - const fixture = TestBed.createComponent(FocusTrapInsidePortal); |
301 |
| - const instance = fixture.componentInstance; |
302 |
| - fixture.detectChanges(); |
303 |
| - const outlet: HTMLElement = fixture.nativeElement.querySelector('.portal-outlet'); |
304 |
| - |
305 |
| - expect(outlet.querySelectorAll('button').length) |
306 |
| - .toBe(0, 'Expected no buttons inside the outlet on init.'); |
307 |
| - expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
308 |
| - .toBe(0, 'Expected no focus trap anchors inside the outlet on init.'); |
309 |
| - |
310 |
| - const portal = new TemplatePortal(instance.template, instance.viewContainerRef); |
311 |
| - instance.portalOutlet.attachTemplatePortal(portal); |
312 |
| - fixture.detectChanges(); |
313 |
| - |
314 |
| - expect(outlet.querySelectorAll('button').length) |
315 |
| - .toBe(1, 'Expected one button inside the outlet after attaching.'); |
316 |
| - expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
317 |
| - .toBe(2, 'Expected two focus trap anchors in the outlet after attaching.'); |
318 |
| - }); |
| 300 | + it('should put anchors inside the outlet when set at the root of a template portal', |
| 301 | + fakeAsync(() => { |
| 302 | + const fixture = TestBed.createComponent(FocusTrapInsidePortal); |
| 303 | + const instance = fixture.componentInstance; |
| 304 | + fixture.detectChanges(); |
| 305 | + const outlet: HTMLElement = fixture.nativeElement.querySelector('.portal-outlet'); |
| 306 | + |
| 307 | + expect(outlet.querySelectorAll('button').length) |
| 308 | + .toBe(0, 'Expected no buttons inside the outlet on init.'); |
| 309 | + expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
| 310 | + .toBe(0, 'Expected no focus trap anchors inside the outlet on init.'); |
| 311 | + |
| 312 | + const portal = new TemplatePortal(instance.template, instance.viewContainerRef); |
| 313 | + instance.portalOutlet.attachTemplatePortal(portal); |
| 314 | + fixture.detectChanges(); |
| 315 | + tick(); |
| 316 | + |
| 317 | + expect(outlet.querySelectorAll('button').length) |
| 318 | + .toBe(1, 'Expected one button inside the outlet after attaching.'); |
| 319 | + expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
| 320 | + .toBe(2, 'Expected two focus trap anchors in the outlet after attaching.'); |
| 321 | + })); |
319 | 322 | });
|
320 | 323 |
|
321 | 324 | /** Gets the currently-focused element while accounting for the shadow DOM. */
|
|
0 commit comments