@stihl-design-system/components
Version:
Welcome to the STIHL Design System react component library.
26 lines (25 loc) • 1.31 kB
TypeScript
/**
* Waits for an SVG icon to be present in the provided HTML container element.
* This function is specifically designed to handle cases where the lazy-loaded DSIcon component is used
* and the test teardown occurs while the icon's loading promise is still pending or resolving.
* This can lead to issues such as tests throwing 'window is not defined' errors. The function
* uses the `waitFor` method from '@testing-library/react' to periodically check for the
* presence of the SVG icon in the container.
*
* @param {HTMLElement} container - The HTML container element in which the SVG icon is expected to load.
* @returns {Promise<void>} A promise that resolves when the SVG icon is present in the container.
*
* @example
* // In a test file
* import { render, screen } from '@testing-library/react';
* import { waitForIcon } from '../../utils/wait-for-icon';
*
* test('should render with default props', async () => {
* const { container } = render(<DSButtonRound>Button</DSButtonRound>);
* await waitForIcon(container); // waitForIcon used here
* const button = screen.getByRole('button');
* expect(button).toBeInTheDocument();
* expectDefaultAttributes(button as HTMLButtonElement);
* });
*/
export declare const waitForIcon: (container: HTMLElement) => Promise<void>;