From d85eea5a7c2b75838156e6b469b860b54f67a225 Mon Sep 17 00:00:00 2001 From: Pranay Kothapalli Date: Wed, 24 Jun 2026 10:44:39 +0530 Subject: [PATCH 1/2] test(Tooltip): lazy mount tooltip content (#1847) --- .../Tooltip/tests/Tooltip.lazyMount.test.tsx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx diff --git a/src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx b/src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx new file mode 100644 index 000000000..680b0c9ae --- /dev/null +++ b/src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import Tooltip from '../Tooltip'; + +describe('Tooltip lazy mount', () => { + test('does not mount tooltip content until opened', () => { + render( + + Hover me + Tooltip label + + ); + + expect(screen.queryByTestId('tooltip-content')).not.toBeInTheDocument(); + }); + + test('mounts content after hover opens the tooltip', async() => { + const user = userEvent.setup(); + + render( + + Hover me + Tooltip label + + ); + + await user.hover(screen.getByText('Hover me')); + expect(screen.getByText('Tooltip label')).toBeInTheDocument(); + }); +}); From 2d2ff003a98e9eb3dc444e1c8c3819342a1aa774 Mon Sep 17 00:00:00 2001 From: Pranay Kothapalli Date: Wed, 24 Jun 2026 16:22:56 +0530 Subject: [PATCH 2/2] test(Tooltip): act and waitFor on lazy mount hover test --- .../ui/Tooltip/tests/Tooltip.lazyMount.test.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx b/src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx index 680b0c9ae..f79be3711 100644 --- a/src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx +++ b/src/components/ui/Tooltip/tests/Tooltip.lazyMount.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render, screen } from '@testing-library/react'; +import { act, render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import Tooltip from '../Tooltip'; @@ -25,7 +25,11 @@ describe('Tooltip lazy mount', () => { ); - await user.hover(screen.getByText('Hover me')); - expect(screen.getByText('Tooltip label')).toBeInTheDocument(); + await act(async() => { + await user.hover(screen.getByText('Hover me')); + }); + await waitFor(() => { + expect(screen.getByText('Tooltip label')).toBeInTheDocument(); + }); }); });