|
1 | 1 | import {Platform} from '@angular/cdk/platform';
|
2 | 2 | import {Component, ViewChild, TemplateRef, ViewContainerRef} from '@angular/core';
|
3 |
| -import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing'; |
| 3 | +import {waitForAsync, ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/testing'; |
4 | 4 | import {PortalModule, CdkPortalOutlet, TemplatePortal} from '@angular/cdk/portal';
|
5 | 5 | import {A11yModule, FocusTrap, CdkTrapFocus} from '../index';
|
6 | 6 |
|
@@ -81,10 +81,11 @@ describe('FocusTrap', () => {
|
81 | 81 | describe('with bindings', () => {
|
82 | 82 | let fixture: ComponentFixture<FocusTrapWithBindings>;
|
83 | 83 |
|
84 |
| - beforeEach(() => { |
| 84 | + beforeEach(fakeAsync(() => { |
85 | 85 | fixture = TestBed.createComponent(FocusTrapWithBindings);
|
86 | 86 | fixture.detectChanges();
|
87 |
| - }); |
| 87 | + tick(); |
| 88 | + })); |
88 | 89 |
|
89 | 90 | it('should clean up its anchor sibling elements on destroy', () => {
|
90 | 91 | const rootElement = fixture.debugElement.nativeElement as HTMLElement;
|
@@ -236,26 +237,28 @@ describe('FocusTrap', () => {
|
236 | 237 |
|
237 | 238 | });
|
238 | 239 |
|
239 |
| - it('should put anchors inside the outlet when set at the root of a template portal', () => { |
240 |
| - const fixture = TestBed.createComponent(FocusTrapInsidePortal); |
241 |
| - const instance = fixture.componentInstance; |
242 |
| - fixture.detectChanges(); |
243 |
| - const outlet: HTMLElement = fixture.nativeElement.querySelector('.portal-outlet'); |
244 |
| - |
245 |
| - expect(outlet.querySelectorAll('button').length) |
246 |
| - .toBe(0, 'Expected no buttons inside the outlet on init.'); |
247 |
| - expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
248 |
| - .toBe(0, 'Expected no focus trap anchors inside the outlet on init.'); |
249 |
| - |
250 |
| - const portal = new TemplatePortal(instance.template, instance.viewContainerRef); |
251 |
| - instance.portalOutlet.attachTemplatePortal(portal); |
252 |
| - fixture.detectChanges(); |
253 |
| - |
254 |
| - expect(outlet.querySelectorAll('button').length) |
255 |
| - .toBe(1, 'Expected one button inside the outlet after attaching.'); |
256 |
| - expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
257 |
| - .toBe(2, 'Expected two focus trap anchors in the outlet after attaching.'); |
258 |
| - }); |
| 240 | + it('should put anchors inside the outlet when set at the root of a template portal', |
| 241 | + fakeAsync(() => { |
| 242 | + const fixture = TestBed.createComponent(FocusTrapInsidePortal); |
| 243 | + const instance = fixture.componentInstance; |
| 244 | + fixture.detectChanges(); |
| 245 | + const outlet: HTMLElement = fixture.nativeElement.querySelector('.portal-outlet'); |
| 246 | + |
| 247 | + expect(outlet.querySelectorAll('button').length) |
| 248 | + .toBe(0, 'Expected no buttons inside the outlet on init.'); |
| 249 | + expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
| 250 | + .toBe(0, 'Expected no focus trap anchors inside the outlet on init.'); |
| 251 | + |
| 252 | + const portal = new TemplatePortal(instance.template, instance.viewContainerRef); |
| 253 | + instance.portalOutlet.attachTemplatePortal(portal); |
| 254 | + fixture.detectChanges(); |
| 255 | + tick(); |
| 256 | + |
| 257 | + expect(outlet.querySelectorAll('button').length) |
| 258 | + .toBe(1, 'Expected one button inside the outlet after attaching.'); |
| 259 | + expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
| 260 | + .toBe(2, 'Expected two focus trap anchors in the outlet after attaching.'); |
| 261 | + })); |
259 | 262 | });
|
260 | 263 |
|
261 | 264 |
|
|
0 commit comments