Files
lucide/packages/astro/tests/Icon.spec.ts
T
Eric FennisandKarsa 8cd4f293f2 fix(packages): only remove aria-hidden when an accessibility prop is set (#5347)
* 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>
2026-12-01 12:56:09 +01:00

104 lines
3.0 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { airVent } from './testIconNodes';
import { createAstroHTMLString, render } from './utils';
import { Icon, Rocket } from '../src/lucide-astro';
describe('Using Icon Component', async () => {
const { container } = await render(Icon, {
props: { iconNode: airVent, size: 48, stroke: 'red', absoluteStrokeWidth: true },
});
it('should render icon and match snapshot', async () => {
expect(container.innerHTML).toMatchSnapshot();
});
it('should render icon based on a iconNode', async () => {
expect(container.innerHTML).toBeDefined();
});
});
describe('Icon Component Accessibility', () => {
it('should have aria-hidden prop when no aria prop is present', async () => {
const { container } = await render(Icon, {
props: {
iconNode: airVent,
size: 48,
stroke: '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 } = await render(Rocket, {
props: {
size: 48,
stroke: 'red',
absoluteStrokeWidth: true,
'aria-label': 'Release icon',
},
});
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
});
it('should not have aria-hidden prop when title prop is present', async () => {
const { container } = await render(Rocket, {
props: {
size: 48,
stroke: 'red',
absoluteStrokeWidth: true,
title: 'Release icon',
},
});
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
});
it('should render a labelled title child and not have aria-hidden prop', async () => {
const { container } = await render(Rocket, {
props: {
role: 'img',
'aria-labelledby': 'warn-title',
},
slots: {
default: createAstroHTMLString(
'<title id="warn-title">Warning: Action cannot be undone</title>',
),
},
});
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
expect(container.firstChild).toHaveAttribute('role', 'img');
expect(container.firstChild).toHaveAttribute('aria-labelledby', 'warn-title');
expect(container.querySelector('title#warn-title')).toHaveTextContent(
'Warning: Action cannot be undone',
);
});
it('should keep aria-hidden prop when there are only children', async () => {
const { container } = await render(Rocket, {
slots: {
default: createAstroHTMLString('<title>Some title</title>'),
},
});
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true');
});
it('should never override aria-hidden prop', async () => {
const { container } = await render(Rocket, {
props: {
size: 48,
stroke: 'red',
absoluteStrokeWidth: true,
'aria-hidden': 'false',
},
});
expect(container.firstChild).toHaveAttribute('aria-hidden', 'false');
});
});