Files
lucide/packages/lucide-preact/tests/context.spec.tsx

89 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-10-16 17:57:23 +02:00
import { render } from '@testing-library/preact';
import { describe, expect, it } from 'vitest';
import { House, LucideProvider } from '../src/lucide-preact';
2025-07-04 16:00:55 +02:00
describe('Using LucideProvider', () => {
it('should render the icon with LucideProvider', () => {
const { container } = render(
<LucideProvider
size={48}
color="red"
>
2025-10-16 17:57:23 +02:00
<House />
</LucideProvider>,
2025-07-04 16:00:55 +02:00
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render the icon with LucideProvider and custom strokeWidth', () => {
const { container } = render(
<LucideProvider
size={48}
color="red"
strokeWidth={4}
>
2025-10-16 17:57:23 +02:00
<House />
</LucideProvider>,
2025-07-04 16:00:55 +02:00
);
const IconComponent = container.firstElementChild;
expect(IconComponent).toHaveAttribute('width', '48');
expect(IconComponent).toHaveAttribute('height', '48');
expect(IconComponent).toHaveAttribute('stroke', 'red');
expect(IconComponent).toHaveAttribute('stroke-width', '4');
});
it('should render the icon with LucideProvider and custom absoluteStrokeWidth', () => {
const { container } = render(
<LucideProvider
size={48}
color="red"
absoluteStrokeWidth
>
2025-10-16 17:57:23 +02:00
<House />
</LucideProvider>,
2025-07-04 16:00:55 +02:00
);
const IconComponent = container.firstElementChild;
expect(IconComponent).toHaveAttribute('stroke-width', '1');
});
it("should override the provider's global props when passing props to the icon", () => {
2025-07-04 16:00:55 +02:00
const { container } = render(
<LucideProvider
size={48}
color="red"
strokeWidth={4}
>
<House
size={24}
color="blue"
strokeWidth={2}
/>
2025-10-16 17:57:23 +02:00
</LucideProvider>,
2025-07-04 16:00:55 +02:00
);
const IconComponent = container.firstElementChild;
expect(IconComponent).toHaveAttribute('width', '24');
expect(IconComponent).toHaveAttribute('height', '24');
expect(IconComponent).toHaveAttribute('stroke', 'blue');
expect(IconComponent).toHaveAttribute('stroke-width', '2');
2025-10-16 17:57:23 +02:00
});
2025-12-12 10:29:24 +01:00
it('should merge class names from LucideProvider and icon props', () => {
const { container } = render(
2025-12-12 10:55:29 +01:00
<LucideProvider class="provider-class">
2025-12-12 10:29:24 +01:00
<House class="icon-class" />
</LucideProvider>,
);
const IconComponent = container.firstElementChild;
expect(IconComponent).toHaveAttribute('class', 'lucide provider-class lucide-house icon-class');
});
2025-10-16 17:57:23 +02:00
});