Skip to content

Commit a0f6d19

Browse files
committed
test(igxOverlay): fix failing test, #1685
1 parent c507883 commit a0f6d19

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

projects/igniteui-angular/src/lib/services/overlay/overlay.spec.ts

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -645,23 +645,21 @@ describe('igxOverlay', () => {
645645
}
646646
}));
647647

648-
it('The shown component is in the center of igx-overlay (visible window) - default.', () => {
648+
it('The shown component is in the center of igx-overlay (visible window) - default.', fakeAsync(() => {
649649
const fixture = TestBed.createComponent(EmptyPageComponent);
650650
fixture.detectChanges();
651651
fixture.componentInstance.overlay.show(SimpleDynamicComponent);
652-
fixture.whenStable().then(() => {
653-
fixture.detectChanges();
654-
const overlayDiv = document.getElementsByClassName(CLASS_OVERLAY_MAIN)[0];
655-
const overlayWrapper = overlayDiv.children[0] as HTMLElement;
656-
const componentEl = overlayWrapper.children[0].children[0];
657-
const wrapperRect = overlayWrapper.getBoundingClientRect();
658-
const componentRect = componentEl.getBoundingClientRect();
659-
expect(wrapperRect.width / 2).toEqual(componentRect.left);
660-
expect(wrapperRect.height / 2).toEqual(componentRect.top);
661-
expect(componentRect.left).toEqual(componentRect.right - componentRect.width);
662-
expect(componentRect.top).toEqual(componentRect.bottom - componentRect.height);
663-
});
664-
});
652+
tick();
653+
const overlayDiv = document.getElementsByClassName(CLASS_OVERLAY_MAIN)[0];
654+
const overlayWrapper = overlayDiv.children[0] as HTMLElement;
655+
const componentEl = overlayWrapper.children[0].children[0];
656+
const wrapperRect = overlayWrapper.getBoundingClientRect();
657+
const componentRect = componentEl.getBoundingClientRect();
658+
expect(wrapperRect.width / 2 - componentRect.width / 2).toEqual(componentRect.left);
659+
expect(wrapperRect.height / 2 - componentRect.height / 2).toEqual(componentRect.top);
660+
expect(componentRect.left).toEqual(componentRect.right - componentRect.width);
661+
expect(componentRect.top).toEqual(componentRect.bottom - componentRect.height);
662+
}));
665663

666664
it('When adding a new instance of a component with the same options, it is rendered exactly on top of the previous one.', () => {
667665
const fixture = TestBed.createComponent(EmptyPageComponent);
@@ -1748,24 +1746,24 @@ describe('igxOverlay', () => {
17481746
});
17491747

17501748
it('Components with 100% width/height should use their initial container\'s properties when placed inside of the overlay element',
1751-
fakeAsync(() => {
1752-
const fixture = TestBed.createComponent(WidthTestOverlayComponent);
1753-
fixture.detectChanges();
1754-
expect(fixture.componentInstance.customComponent).toBeDefined();
1755-
expect(fixture.componentInstance.customComponent.nativeElement.style.width).toEqual('100%');
1756-
expect(fixture.componentInstance.customComponent.nativeElement.getBoundingClientRect().width).toEqual(420);
1757-
expect(fixture.componentInstance.customComponent.nativeElement.style.height).toEqual('100%');
1758-
expect(fixture.componentInstance.customComponent.nativeElement.getBoundingClientRect().height).toEqual(280);
1759-
fixture.componentInstance.buttonElement.nativeElement.click();
1760-
tick();
1761-
const overlayContent = document.getElementsByClassName(CLASS_OVERLAY_CONTENT)[0] as HTMLElement;
1762-
const overlayChild = overlayContent.lastElementChild as HTMLElement;
1763-
expect(overlayChild).toBeDefined();
1764-
expect(overlayChild.style.width).toEqual('100%');
1765-
expect(overlayChild.getBoundingClientRect().width).toEqual(420);
1766-
expect(overlayChild.style.height).toEqual('100%');
1767-
expect(overlayChild.getBoundingClientRect().height).toEqual(280);
1768-
}));
1749+
fakeAsync(() => {
1750+
const fixture = TestBed.createComponent(WidthTestOverlayComponent);
1751+
fixture.detectChanges();
1752+
expect(fixture.componentInstance.customComponent).toBeDefined();
1753+
expect(fixture.componentInstance.customComponent.nativeElement.style.width).toEqual('100%');
1754+
expect(fixture.componentInstance.customComponent.nativeElement.getBoundingClientRect().width).toEqual(420);
1755+
expect(fixture.componentInstance.customComponent.nativeElement.style.height).toEqual('100%');
1756+
expect(fixture.componentInstance.customComponent.nativeElement.getBoundingClientRect().height).toEqual(280);
1757+
fixture.componentInstance.buttonElement.nativeElement.click();
1758+
tick();
1759+
const overlayContent = document.getElementsByClassName(CLASS_OVERLAY_CONTENT)[0] as HTMLElement;
1760+
const overlayChild = overlayContent.lastElementChild as HTMLElement;
1761+
expect(overlayChild).toBeDefined();
1762+
expect(overlayChild.style.width).toEqual('100%');
1763+
expect(overlayChild.getBoundingClientRect().width).toEqual(420);
1764+
expect(overlayChild.style.height).toEqual('100%');
1765+
expect(overlayChild.getBoundingClientRect().height).toEqual(280);
1766+
}));
17691767
});
17701768
});
17711769

0 commit comments

Comments
 (0)