diff --git a/src/lib/util/text.test.ts b/src/lib/util/text.test.ts index 88967da7..0ca95fd1 100644 --- a/src/lib/util/text.test.ts +++ b/src/lib/util/text.test.ts @@ -4,6 +4,8 @@ import { calculateHeaderSize, calculateInlineTitleSize, isHeader, + isPx, + pxToRem, } from './text'; describe('calculateFontTextSize', () => { @@ -62,3 +64,33 @@ describe('calculateHeaderSize', () => { expect(calculateHeaderSize('header-1')).toBe(32); }); }); + +describe('pxToRem', () => { + it('should convert px to rem', () => { + expect(pxToRem(16)).toBe(1); + expect(pxToRem(24)).toBe(1.5); + expect(pxToRem(32)).toBe(2); + }); + + it('should convert px to rem with different base value', () => { + expect(pxToRem(16, 20)).toBe(0.8); + expect(pxToRem(24, 20)).toBe(1.2); + expect(pxToRem(32, 20)).toBe(1.6); + }); +}); + +describe('isPx', () => { + it('should return `true` when value is in px format', () => { + expect(isPx('16px')).toBe(true); + expect(isPx('0px')).toBe(true); + expect(isPx('5903px')).toBe(true); + }); + + it('should return `false` when value is in not px format', () => { + expect(isPx('px')).toBe(false); + expect(isPx('')).toBe(false); + expect(isPx('16rem')).toBe(false); + expect(isPx('16em')).toBe(false); + expect(isPx('16ch')).toBe(false); + }); +}); diff --git a/src/lib/util/text.ts b/src/lib/util/text.ts index a86c554c..0b331205 100644 --- a/src/lib/util/text.ts +++ b/src/lib/util/text.ts @@ -58,7 +58,7 @@ const calculateHeaderSize = (header: HTMLHeader | HeaderToken): number => { } // If there is some `calc` operation going on, it has to be evaluated. - if (headerComputedStyle.contains('calc')) { + if (headerComputedStyle.includes('calc')) { const temp = document.createElement('div'); temp.style.setProperty('font-size', `var(--${htmlHeader}-size)`);