mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-15 21:37:43 +01:00
* Add useIconComponent, lucide-react * Add concept useIconComponent * add useIconComponents to packages * Add icon component * Add icon component * Add tests for react packages * Reset changes in icons * Add types * Add support for Icon components in Lucide Vue Next * update tests * Update tests * Enable Svelte component * Fix lucide-react-native tests * Update Solid package * update snapshots * Add docs * add docs * Update tests * Formatting * Formatting * Update package lock * Remove `useIconComponent` * Update guides * Update exports preact and solid package * Formatting * Format createIcons.ts * Add lucide lab repo link in docs
101 lines
3.2 KiB
TypeScript
101 lines
3.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { render, cleanup } from '@testing-library/preact';
|
|
import { Pen, Edit2, Grid, Droplet } from '../src/lucide-preact';
|
|
import defaultAttributes from '../src/defaultAttributes';
|
|
|
|
type AttributesAssertion = { attributes: Record<string, { value: string }> };
|
|
|
|
describe('Using lucide icon components', () => {
|
|
it('should render an component', () => {
|
|
const { container } = render(<Grid />);
|
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render the icon with the default attributes', () => {
|
|
const { container } = render(<Grid />);
|
|
|
|
const SVGElement = container.firstElementChild;
|
|
|
|
expect(SVGElement).toHaveAttribute('xmlns', defaultAttributes.xmlns);
|
|
expect(SVGElement).toHaveAttribute('width', String(defaultAttributes.width));
|
|
expect(SVGElement).toHaveAttribute('height', String(defaultAttributes.height));
|
|
expect(SVGElement).toHaveAttribute('viewBox', defaultAttributes.viewBox);
|
|
expect(SVGElement).toHaveAttribute('fill', defaultAttributes.fill);
|
|
expect(SVGElement).toHaveAttribute('stroke', defaultAttributes.stroke);
|
|
expect(SVGElement).toHaveAttribute('stroke-width', String(defaultAttributes['stroke-width']));
|
|
expect(SVGElement).toHaveAttribute('stroke-linecap', defaultAttributes['stroke-linecap']);
|
|
expect(SVGElement).toHaveAttribute('stroke-linejoin', defaultAttributes['stroke-linejoin']);
|
|
});
|
|
|
|
it('should adjust the size, stroke color and stroke width', () => {
|
|
const { container } = render(
|
|
<Grid
|
|
size={48}
|
|
stroke="red"
|
|
strokeWidth={4}
|
|
/>,
|
|
);
|
|
|
|
const SVGElement = container.firstElementChild;
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke', 'red');
|
|
expect(SVGElement).toHaveAttribute('width', '48');
|
|
expect(SVGElement).toHaveAttribute('height', '48');
|
|
expect(SVGElement).toHaveAttribute('stroke-width', '4');
|
|
expect(container.innerHTML).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render the alias icon', () => {
|
|
const { container } = render(
|
|
<Pen
|
|
size={48}
|
|
stroke="red"
|
|
strokeWidth={4}
|
|
/>,
|
|
);
|
|
|
|
const PenIconRenderedHTML = container.innerHTML;
|
|
|
|
cleanup();
|
|
|
|
const { container: Edit2Container } = render(
|
|
<Edit2
|
|
size={48}
|
|
stroke="red"
|
|
strokeWidth={4}
|
|
/>,
|
|
);
|
|
|
|
expect(PenIconRenderedHTML).toBe(Edit2Container.innerHTML);
|
|
});
|
|
|
|
it('should not scale the strokeWidth when absoluteStrokeWidth is set', () => {
|
|
const { container } = render(
|
|
<Grid
|
|
size={48}
|
|
stroke="red"
|
|
absoluteStrokeWidth
|
|
/>,
|
|
);
|
|
|
|
const SVGElement = container.firstElementChild;
|
|
|
|
expect(SVGElement).toHaveAttribute('stroke', 'red');
|
|
expect(SVGElement).toHaveAttribute('width', '48');
|
|
expect(SVGElement).toHaveAttribute('height', '48');
|
|
expect(SVGElement).toHaveAttribute('stroke-width', '1');
|
|
|
|
expect(container.innerHTML).toMatchSnapshot();
|
|
});
|
|
|
|
it('should apply all classes to the element', () => {
|
|
const testClass = 'my-class';
|
|
const { container } = render(<Droplet class={testClass} />);
|
|
|
|
expect(container.firstChild).toHaveClass(testClass);
|
|
expect(container.firstChild).toHaveClass('lucide');
|
|
expect(container.firstChild).toHaveClass('lucide-droplet');
|
|
});
|
|
});
|