mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-12-03 16:59:42 +00:00
* Adjust accessibility behaviour for title elements * Adjust angular package as well * Fix types * fix(packages/angular): use fixture.whenStable instead of triggering change detection manually detectChanges() explicitly forces a check, so it can mask missing automatic change detection * test(packages/angular): add test for non-signal bound aria attribute * fix(angular): preserve explicit aria-hidden and support input bindings --------- Co-authored-by: Karsa <contact@karsa.org>
136 lines
3.6 KiB
TypeScript
136 lines
3.6 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { render } from '@testing-library/vue';
|
|
import { defineComponent } from 'vue';
|
|
|
|
import { airVent } from './testIconNodes';
|
|
import { Icon } from '../src/lucide-vue';
|
|
|
|
describe('Using Icon Component', () => {
|
|
const airVentIcon = { name: 'air-vent', node: airVent, size: 24 };
|
|
|
|
it('should render icon based on an icon node', async () => {
|
|
const { container } = render(Icon, {
|
|
props: {
|
|
iconNode: airVent,
|
|
name: 'AirVent',
|
|
size: 48,
|
|
color: 'red',
|
|
absoluteStrokeWidth: true,
|
|
},
|
|
});
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render when iconNode is passed as the kebab-case icon-node prop', async () => {
|
|
const { container } = render(Icon, {
|
|
props: {
|
|
'icon-node': airVent,
|
|
name: 'AirVent',
|
|
},
|
|
});
|
|
|
|
expect(container.firstChild).toBeDefined();
|
|
expect(container.querySelector('svg')).toBeTruthy();
|
|
});
|
|
|
|
it('should render icon and match snapshot', async () => {
|
|
const { container } = render(Icon, {
|
|
props: {
|
|
icon: airVentIcon,
|
|
size: 48,
|
|
color: 'red',
|
|
absoluteStrokeWidth: true,
|
|
},
|
|
});
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('should update when reactive props change', async () => {
|
|
const wrapper = defineComponent({
|
|
components: { Icon },
|
|
props: {
|
|
size: Number,
|
|
},
|
|
setup() {
|
|
return { airVentIcon };
|
|
},
|
|
template: '<Icon :icon="airVentIcon" :size="size" />',
|
|
});
|
|
|
|
const { container, rerender } = render(wrapper, { props: { size: 24 } });
|
|
|
|
expect(container.firstChild).toHaveAttribute('width', '24');
|
|
expect(container.firstChild).toHaveAttribute('height', '24');
|
|
|
|
await rerender({ size: 48 });
|
|
|
|
expect(container.firstChild).toHaveAttribute('width', '48');
|
|
expect(container.firstChild).toHaveAttribute('height', '48');
|
|
});
|
|
});
|
|
|
|
describe('Icon Component Accessibility', () => {
|
|
it('should have aria-hidden prop when no aria prop is present', async () => {
|
|
const { container } = render(Icon, {
|
|
props: {
|
|
iconNode: airVent,
|
|
name: 'AirVent',
|
|
size: 48,
|
|
color: 'red',
|
|
absoluteStrokeWidth: true,
|
|
},
|
|
});
|
|
|
|
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true');
|
|
});
|
|
|
|
it('should not have aria-hidden prop when aria prop is present', async () => {
|
|
const { container } = render(Icon, {
|
|
props: {
|
|
iconNode: airVent,
|
|
name: 'AirVent',
|
|
size: 48,
|
|
color: 'red',
|
|
absoluteStrokeWidth: true,
|
|
'aria-label': 'Air conditioning',
|
|
},
|
|
});
|
|
|
|
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
|
|
expect(container.firstChild).toHaveAttribute('aria-label', 'Air conditioning');
|
|
});
|
|
|
|
it('should not have aria-hidden prop when title prop is present', async () => {
|
|
const { container } = render(Icon, {
|
|
props: {
|
|
iconNode: airVent,
|
|
name: 'AirVent',
|
|
size: 48,
|
|
color: 'red',
|
|
absoluteStrokeWidth: true,
|
|
// @ts-expect-error
|
|
title: 'Air conditioning',
|
|
},
|
|
});
|
|
|
|
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
|
|
});
|
|
|
|
it('should never override aria-hidden prop', async () => {
|
|
const { container } = render(Icon, {
|
|
props: {
|
|
iconNode: airVent,
|
|
name: 'AirVent',
|
|
size: 48,
|
|
color: 'red',
|
|
absoluteStrokeWidth: true,
|
|
'aria-hidden': 'false',
|
|
},
|
|
});
|
|
|
|
expect(container.firstChild).toHaveAttribute('aria-hidden', 'false');
|
|
});
|
|
});
|