mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-14 13:58:21 +00:00
test(lucide-react): add tests for DynamicIcon fallback and ref forwarding (#4966)
* test(lucide-react): add tests for DynamicIcon fallback and ref forwarding * style(lucide-react): format DynamicIcon test with Prettier --------- Co-authored-by: grzdev <grzdev@users.noreply.github.com> Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
co-authored by
grzdev
Eric Fennis
parent
edaf5070d7
commit
949bc6d61f
@@ -52,4 +52,33 @@ describe('Using DynamicIcon Component', () => {
|
||||
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should render fallback component while icon is loading', () => {
|
||||
const FallbackComponent = () => <span data-testid="fallback">Loading...</span>;
|
||||
const { getByTestId } = render(
|
||||
<DynamicIcon
|
||||
name="smile"
|
||||
fallback={FallbackComponent}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(getByTestId('fallback')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should forward ref to the rendered svg element', async () => {
|
||||
const ref = { current: null as SVGSVGElement | null };
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<DynamicIcon
|
||||
ref={ref}
|
||||
name="smile"
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(ref.current).toBeInstanceOf(SVGSVGElement);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user