diff --git a/src/lib/directives/ng2-fittext.directive.ts b/src/lib/directives/ng2-fittext.directive.ts index 2c435b8..24ee24e 100644 --- a/src/lib/directives/ng2-fittext.directive.ts +++ b/src/lib/directives/ng2-fittext.directive.ts @@ -137,7 +137,7 @@ export class Ng2FittextDirective } } - private getStartFontSizeFromHeight(): number { + getStartFontSizeFromHeight(): number { return this.container ? this.container.clientHeight : this.el.nativeElement.parentElement.clientHeight; diff --git a/src/lib/directives/specs/ng2-fittext.directive.spec.ts b/src/lib/directives/specs/ng2-fittext.directive.spec.ts index 84ecdc3..872cfc5 100644 --- a/src/lib/directives/specs/ng2-fittext.directive.spec.ts +++ b/src/lib/directives/specs/ng2-fittext.directive.spec.ts @@ -144,4 +144,28 @@ describe('Class: Ng2FittextDirective', () => { ).toBe(true); }); }); + + describe('Method: getStartFontSizeFromHeight', () => { + it('Should return the container clientHeight value if the container is present', () => { + const containerClientHeight = 10; + ng2FittextDirective.container = { + clientHeight: containerClientHeight, + } as HTMLElement; + expect(ng2FittextDirective.getStartFontSizeFromHeight()).toEqual( + containerClientHeight + ); + }); + + it('Should return the parentElement clientHeight value if no container is present', () => { + const parentlientHeight = 11; + elMock.nativeElement = { + parentElement: { + clientHeight: parentlientHeight, + }, + } as HTMLElement; + expect(ng2FittextDirective.getStartFontSizeFromHeight()).toEqual( + parentlientHeight + ); + }); + }); });