diff --git a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay-handler.spec.ts b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay-handler.spec.ts index f5b1c4102a..3c82f73bae 100644 --- a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay-handler.spec.ts +++ b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay-handler.spec.ts @@ -70,6 +70,11 @@ export class NbMockDynamicOverlay { this._componentType = componentType; } + setContentAndContext(content: NbOverlayContent, context: Object) { + this._content = content; + this._context = context; + } + setPositionStrategy(positionStrategy: NbAdjustableConnectedPositionStrategy) { this._positionStrategy = positionStrategy; } diff --git a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts index 1bdc1fa8fa..a353db86b1 100644 --- a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts +++ b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts @@ -1,4 +1,4 @@ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed, tick } from '@angular/core/testing'; import { Component, ComponentFactoryResolver, Input } from '@angular/core'; import { Subject } from 'rxjs'; import { ScrollStrategy } from '@angular/cdk/overlay'; @@ -227,33 +227,35 @@ describe('dynamic-overlay', () => { expect(dynamicOverlay.getContainer()).toBe(container as any); }); - it('should set content when shown', () => { + it('should set content when shown', fakeAsync(() => { const renderContentSpy = spyOn(instance, 'renderContent').and.callThrough(); const updatePositionSpy = spyOn(ref, 'updatePosition').and.callThrough(); dynamicOverlay.show(); const newContent = 'new content'; dynamicOverlay.setContent(newContent); + tick(); // we have setTimeout here expect(instance.content).toBe(newContent); expect(renderContentSpy).toHaveBeenCalledTimes(2); expect(updatePositionSpy).toHaveBeenCalledTimes(1); - }); + })); - it('should set context when shown', () => { + it('should set context when shown', fakeAsync(() => { const renderContentSpy = spyOn(instance, 'renderContent').and.callThrough(); const updatePositionSpy = spyOn(ref, 'updatePosition').and.callThrough(); dynamicOverlay.show(); const newContext = { some: 'thing' }; dynamicOverlay.setContext(newContext); + tick(); // we have setTimeout here expect(instance.context).toBe(newContext); expect(renderContentSpy).toHaveBeenCalledTimes(2); expect(updatePositionSpy).toHaveBeenCalledTimes(1); - }); + })); - it('should set context & content when shown', () => { + it('should set context & content when shown', fakeAsync(() => { const renderContentSpy = spyOn(instance, 'renderContent').and.callThrough(); const updatePositionSpy = spyOn(ref, 'updatePosition').and.callThrough(); @@ -261,13 +263,15 @@ describe('dynamic-overlay', () => { const newContext = { some: 'thing' }; const newContent = 'new content'; dynamicOverlay.setContent(newContent); + tick(); // we have setTimeout here dynamicOverlay.setContext(newContext); + tick(); // we have setTimeout here expect(instance.context).toBe(newContext); expect(instance.content).toBe(newContent); expect(renderContentSpy).toHaveBeenCalledTimes(3); expect(updatePositionSpy).toHaveBeenCalledTimes(2); - }); + })); it('should set component', () => { const detachSpy = spyOn(ref, 'detach').and.callThrough(); diff --git a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.ts b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.ts index 65701b0a56..9b3c614eb6 100644 --- a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.ts +++ b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.ts @@ -43,8 +43,7 @@ export class NbDynamicOverlay { context: Object, positionStrategy: NbAdjustableConnectedPositionStrategy) { - this.setContext(context); - this.setContent(content); + this.setContentAndContext(content, context); this.setComponent(componentType); this.setPositionStrategy(positionStrategy); @@ -70,7 +69,6 @@ export class NbDynamicOverlay { setContentAndContext(content: NbOverlayContent, context: Object) { this.content = content; this.context = context; - if (this.container) { this.updateContext(); }