Skip to content

Commit

Permalink
Update pxToEm
Browse files Browse the repository at this point in the history
- Additional check for finite values for pxToEm
- Additional test case for Infinity numeric value
  • Loading branch information
heyjul3s committed Feb 10, 2021
1 parent 0fc803d commit fee58bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/pxtoem/__tests__/pxtoem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ describe('@artifak/pxtoem', () => {
expect(pxToEm(NaN as any)).toEqual('0em');
});

it('returns a string of "0em" when provided with Infinity as value', () => {
expect(pxToEm(Infinity)).toEqual('0em');
});

it('returns a string EM value of 3 when provided a numeric value of "48"', () => {
expect(pxToEm(48)).toEqual('3em');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/pxtoem/src/pxtoem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getPxNumericValue(size: number | string): number {
return extractPxNumericValue(size as string);
}

if (!!size) {
if (!!size && isFinite(size as number)) {
return size as number;
}

Expand Down

0 comments on commit fee58bc

Please sign in to comment.