|
| 1 | +import { render } from '@testing-library/preact'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | +import { House, LucideProvider } from '../src/lucide-preact'; |
| 4 | + |
| 5 | +describe('Using LucideProvider', () => { |
| 6 | + it('should render the icon with LucideProvider', () => { |
| 7 | + const { container } = render( |
| 8 | + <LucideProvider |
| 9 | + size={48} |
| 10 | + color="red" |
| 11 | + > |
| 12 | + <House /> |
| 13 | + </LucideProvider>, |
| 14 | + ); |
| 15 | + |
| 16 | + expect(container.firstChild).toMatchSnapshot(); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should render the icon with LucideProvider and custom strokeWidth', () => { |
| 20 | + const { container } = render( |
| 21 | + <LucideProvider |
| 22 | + size={48} |
| 23 | + color="red" |
| 24 | + strokeWidth={4} |
| 25 | + > |
| 26 | + <House /> |
| 27 | + </LucideProvider>, |
| 28 | + ); |
| 29 | + |
| 30 | + const IconComponent = container.firstElementChild; |
| 31 | + |
| 32 | + expect(IconComponent).toHaveAttribute('width', '48'); |
| 33 | + expect(IconComponent).toHaveAttribute('height', '48'); |
| 34 | + expect(IconComponent).toHaveAttribute('stroke', 'red'); |
| 35 | + expect(IconComponent).toHaveAttribute('stroke-width', '4'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should render the icon with LucideProvider and custom absoluteStrokeWidth', () => { |
| 39 | + const { container } = render( |
| 40 | + <LucideProvider |
| 41 | + size={48} |
| 42 | + color="red" |
| 43 | + absoluteStrokeWidth |
| 44 | + > |
| 45 | + <House /> |
| 46 | + </LucideProvider>, |
| 47 | + ); |
| 48 | + |
| 49 | + const IconComponent = container.firstElementChild; |
| 50 | + |
| 51 | + expect(IconComponent).toHaveAttribute('stroke-width', '1'); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should override the provider's global props when passing props to the icon", () => { |
| 55 | + const { container } = render( |
| 56 | + <LucideProvider |
| 57 | + size={48} |
| 58 | + color="red" |
| 59 | + strokeWidth={4} |
| 60 | + > |
| 61 | + <House |
| 62 | + size={24} |
| 63 | + color="blue" |
| 64 | + strokeWidth={2} |
| 65 | + /> |
| 66 | + </LucideProvider>, |
| 67 | + ); |
| 68 | + |
| 69 | + const IconComponent = container.firstElementChild; |
| 70 | + |
| 71 | + expect(IconComponent).toHaveAttribute('width', '24'); |
| 72 | + expect(IconComponent).toHaveAttribute('height', '24'); |
| 73 | + expect(IconComponent).toHaveAttribute('stroke', 'blue'); |
| 74 | + expect(IconComponent).toHaveAttribute('stroke-width', '2'); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should merge class names from LucideProvider and icon props', () => { |
| 78 | + const { container } = render( |
| 79 | + <LucideProvider class="provider-class"> |
| 80 | + <House class="icon-class" /> |
| 81 | + </LucideProvider>, |
| 82 | + ); |
| 83 | + |
| 84 | + const IconComponent = container.firstElementChild; |
| 85 | + |
| 86 | + expect(IconComponent).toHaveAttribute('class', 'lucide provider-class lucide-house icon-class'); |
| 87 | + }); |
| 88 | +}); |
0 commit comments