|
1 | 1 | import {Platform} from '@angular/cdk/platform';
|
2 | 2 | import {Component, ViewChild, TemplateRef, ViewContainerRef} from '@angular/core';
|
3 |
| -import {async, ComponentFixture, TestBed} from '@angular/core/testing'; |
| 3 | +import {async, 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;
|
@@ -212,26 +213,28 @@ describe('FocusTrap', () => {
|
212 | 213 |
|
213 | 214 | });
|
214 | 215 |
|
215 |
| - it('should put anchors inside the outlet when set at the root of a template portal', () => { |
216 |
| - const fixture = TestBed.createComponent(FocusTrapInsidePortal); |
217 |
| - const instance = fixture.componentInstance; |
218 |
| - fixture.detectChanges(); |
219 |
| - const outlet: HTMLElement = fixture.nativeElement.querySelector('.portal-outlet'); |
220 |
| - |
221 |
| - expect(outlet.querySelectorAll('button').length) |
222 |
| - .toBe(0, 'Expected no buttons inside the outlet on init.'); |
223 |
| - expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
224 |
| - .toBe(0, 'Expected no focus trap anchors inside the outlet on init.'); |
225 |
| - |
226 |
| - const portal = new TemplatePortal(instance.template, instance.viewContainerRef); |
227 |
| - instance.portalOutlet.attachTemplatePortal(portal); |
228 |
| - fixture.detectChanges(); |
229 |
| - |
230 |
| - expect(outlet.querySelectorAll('button').length) |
231 |
| - .toBe(1, 'Expected one button inside the outlet after attaching.'); |
232 |
| - expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
233 |
| - .toBe(2, 'Expected two focus trap anchors in the outlet after attaching.'); |
234 |
| - }); |
| 216 | + it('should put anchors inside the outlet when set at the root of a template portal', |
| 217 | + fakeAsync(() => { |
| 218 | + const fixture = TestBed.createComponent(FocusTrapInsidePortal); |
| 219 | + const instance = fixture.componentInstance; |
| 220 | + fixture.detectChanges(); |
| 221 | + const outlet: HTMLElement = fixture.nativeElement.querySelector('.portal-outlet'); |
| 222 | + |
| 223 | + expect(outlet.querySelectorAll('button').length) |
| 224 | + .toBe(0, 'Expected no buttons inside the outlet on init.'); |
| 225 | + expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
| 226 | + .toBe(0, 'Expected no focus trap anchors inside the outlet on init.'); |
| 227 | + |
| 228 | + const portal = new TemplatePortal(instance.template, instance.viewContainerRef); |
| 229 | + instance.portalOutlet.attachTemplatePortal(portal); |
| 230 | + fixture.detectChanges(); |
| 231 | + tick(); |
| 232 | + |
| 233 | + expect(outlet.querySelectorAll('button').length) |
| 234 | + .toBe(1, 'Expected one button inside the outlet after attaching.'); |
| 235 | + expect(outlet.querySelectorAll('.cdk-focus-trap-anchor').length) |
| 236 | + .toBe(2, 'Expected two focus trap anchors in the outlet after attaching.'); |
| 237 | + })); |
235 | 238 | });
|
236 | 239 |
|
237 | 240 |
|
|
0 commit comments