mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-12-03 16:59:42 +00:00
`absoluteStrokeWidth` scales the stroke by `Number(size)`, so a CSS unit such as `1em` produced `NaN` and a size of `0` produced `Infinity` – both invalid as a `stroke-width` attribute. Fall back to the unscaled stroke width whenever the conversion isn't finite, so the deprecated prop degrades rather than breaking the rendered icon.
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import buildLucideIconNode from '../src/build/buildLucideIconNode';
|
|
|
|
const icon = { name: 'circle', size: 24, node: [] };
|
|
|
|
const strokeWidthOf = (params: Parameters<typeof buildLucideIconNode>[1]) =>
|
|
buildLucideIconNode(icon, params)[1]['stroke-width'];
|
|
|
|
describe('buildLucideIconNode absoluteStrokeWidth', () => {
|
|
it('scales the stroke width for numeric sizes', () => {
|
|
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: 48 })).toBe(1);
|
|
});
|
|
|
|
it('falls back to the unscaled width for a CSS unit size', () => {
|
|
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: '1em' })).toBe(2);
|
|
});
|
|
|
|
it('falls back to the unscaled width for a non-numeric stroke width', () => {
|
|
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: '1em', size: 48 })).toBe('1em');
|
|
});
|
|
|
|
it('falls back to the unscaled width for a zero size', () => {
|
|
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: 0 })).toBe(2);
|
|
});
|
|
|
|
it('leaves the stroke width alone when not absolute', () => {
|
|
expect(strokeWidthOf({ strokeWidth: 2, size: 48 })).toBe(2);
|
|
});
|
|
});
|