Added Ng2FittextDirective class unit tests #32

Merged
giacomoferlaino merged 11 commits from master into master 2020-03-16 11:28:52 +00:00
2 changed files with 25 additions and 1 deletions
Showing only changes of commit 2e73f1c9ee - Show all commits

View file

@ -137,7 +137,7 @@ export class Ng2FittextDirective
}
}
private getStartFontSizeFromHeight(): number {
getStartFontSizeFromHeight(): number {
return this.container
? this.container.clientHeight
: this.el.nativeElement.parentElement.clientHeight;

View file

@ -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
);
});
});
});