Skip to content

Commit 0791e07

Browse files
committed
fix: tests
1 parent 132f6c4 commit 0791e07

6 files changed

Lines changed: 48 additions & 28 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@rollup/plugin-typescript": "12.3.0",
6565
"@testing-library/dom": "^10.4.1",
6666
"@testing-library/jest-dom": "6.9.1",
67-
"@testing-library/react": "^16.3.0",
67+
"@testing-library/react": "16.3.0",
6868
"@testing-library/user-event": "14.6.1",
6969
"@types/css": "0.0.38",
7070
"@types/css-modules": "1.0.5",
@@ -98,8 +98,8 @@
9898
"postcss": "8.5.10",
9999
"prettier": "3.8.3",
100100
"process": "0.11.10",
101-
"react": "^19.0.0",
102-
"react-dom": "^19.0.0",
101+
"react": "19.0.0",
102+
"react-dom": "19.0.0",
103103
"rimraf": "6.1.3",
104104
"rollup": "4.60.1",
105105
"rollup-plugin-analyzer": "4.0.0",

src/components/Tooltip/use-tooltip-anchors.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const useTooltipAnchors = ({
5656
} catch {
5757
return false
5858
}
59-
}, [activeAnchor, selector])
59+
// eslint-disable-next-line react-hooks/exhaustive-deps
60+
}, [activeAnchor, selector, anchorElements])
6061

6162
useEffect(() => {
6263
if (!selector || !trackAnchors) {

src/test/__snapshots__/tooltip-props.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ exports[`tooltip props tooltip with float 1`] = `
114114
</div>
115115
<div
116116
class="react-tooltip-arrow"
117-
style="--rt-arrow-size: 8px; left: -1px; bottom: -3px;"
117+
style="--rt-arrow-size: 8px; left: 0px; bottom: -3px;"
118118
/>
119119
</div>
120120
</div>

src/test/tooltip-attributes.spec.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ describe('tooltip attributes', () => {
3636

3737
await userEvent.hover(anchorElement)
3838

39-
const tooltip = await screen.findByRole('tooltip')
40-
expect(tooltip).toHaveAttribute('style')
41-
42-
expect(anchorElement).toHaveAttribute('data-tooltip-content')
4339
await waitFor(() => {
40+
const tooltip = screen.getByRole('tooltip')
41+
expect(tooltip).toHaveAttribute('style')
4442
expect(anchorElement).toHaveAttribute('aria-describedby', 'basic-example-attr')
4543
})
46-
expect(tooltip).toBeInTheDocument()
44+
45+
expect(anchorElement).toHaveAttribute('data-tooltip-content')
46+
expect(screen.getByRole('tooltip')).toBeInTheDocument()
4747
})
4848

4949
test('tooltip with place', async () => {
@@ -58,15 +58,15 @@ describe('tooltip attributes', () => {
5858

5959
await userEvent.hover(anchorElement)
6060

61-
const tooltip = await screen.findByRole('tooltip')
62-
expect(tooltip).toHaveAttribute('style')
63-
64-
expect(anchorElement).toHaveAttribute('data-tooltip-place')
65-
expect(anchorElement).toHaveAttribute('data-tooltip-content')
6661
await waitFor(() => {
62+
const tooltip = screen.getByRole('tooltip')
63+
expect(tooltip).toHaveAttribute('style')
6764
expect(anchorElement).toHaveAttribute('aria-describedby', 'example-place-attr')
6865
})
69-
expect(tooltip).toBeInTheDocument()
66+
67+
expect(anchorElement).toHaveAttribute('data-tooltip-place')
68+
expect(anchorElement).toHaveAttribute('data-tooltip-content')
69+
expect(screen.getByRole('tooltip')).toBeInTheDocument()
7070
})
7171

7272
test('tooltip with class name', async () => {
@@ -81,13 +81,13 @@ describe('tooltip attributes', () => {
8181

8282
await userEvent.hover(anchorElement)
8383

84-
const tooltip = await screen.findByRole('tooltip')
85-
expect(tooltip).toHaveClass('tooltip-class-name')
86-
87-
expect(anchorElement).toHaveAttribute('data-tooltip-class-name')
8884
await waitFor(() => {
85+
const tooltip = screen.getByRole('tooltip')
86+
expect(tooltip).toHaveClass('tooltip-class-name')
8987
expect(anchorElement).toHaveAttribute('aria-describedby', 'example-class-name-attr')
9088
})
91-
expect(tooltip).toBeInTheDocument()
89+
90+
expect(anchorElement).toHaveAttribute('data-tooltip-class-name')
91+
expect(screen.getByRole('tooltip')).toBeInTheDocument()
9292
})
9393
})

src/test/tooltip-close-and-delay-behavior.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ describe('tooltip close and delay behavior', () => {
7777
expect(screen.getByRole('tooltip')).toBeInTheDocument()
7878

7979
fireEvent.mouseLeave(tooltip)
80+
advanceTimers(100)
81+
// Second advancement needed: the first fires handleShow(false) timeout,
82+
// which creates the missedTransitionTimer during the effect flush
83+
advanceTimers(100)
8084
await waitForTooltipToClose('clickable-no-click-test')
8185
})
8286

src/test/tooltip-props.spec.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen, waitFor } from '@testing-library/react'
1+
import { render, screen, waitFor, fireEvent, act } from '@testing-library/react'
22
import userEvent from '@testing-library/user-event'
33
import '@testing-library/jest-dom'
44
import { TooltipController as Tooltip } from '../components/TooltipController'
@@ -160,15 +160,27 @@ describe('tooltip props', () => {
160160
const { container } = render(<TooltipProps id="example-float" content="Hello World!" float />)
161161
const anchorElement = screen.getByText('Lorem Ipsum')
162162

163-
await userEvent.hover(anchorElement)
163+
// Use act to ensure state updates and effects are flushed between steps
164+
await act(async () => {
165+
fireEvent.mouseEnter(anchorElement)
166+
})
167+
168+
// Fire pointermove after activeAnchor is set (batching in older React prevents it during hover)
169+
await act(async () => {
170+
anchorElement.dispatchEvent(
171+
new MouseEvent('pointermove', { clientX: 5, clientY: 0, bubbles: true }),
172+
)
173+
// Allow microtask (computeTooltipPosition promise) to resolve
174+
await new Promise((r) => setTimeout(r, 50))
175+
})
164176

165-
const tooltip = await screen.findByRole('tooltip')
166-
expect(tooltip).toHaveAttribute('style')
167177
await waitFor(() => {
178+
const tooltip = screen.getByRole('tooltip')
179+
expect(tooltip).toHaveAttribute('style')
168180
expect(anchorElement).toHaveAttribute('aria-describedby', 'example-float')
169181
})
170182

171-
expect(tooltip).toBeInTheDocument()
183+
expect(screen.getByRole('tooltip')).toBeInTheDocument()
172184
expect(container).toMatchSnapshot()
173185
})
174186

@@ -197,9 +209,12 @@ describe('tooltip props', () => {
197209
const anchorElement = screen.getByText('Lorem Ipsum')
198210
await userEvent.hover(anchorElement)
199211

200-
const tooltip = await screen.findByRole('tooltip')
212+
await waitFor(() => {
213+
const tooltip = screen.getByRole('tooltip')
214+
expect(tooltip).toBeInTheDocument()
215+
expect(tooltip).toHaveClass('react-tooltip__show')
216+
})
201217

202-
expect(tooltip).toBeInTheDocument()
203218
expect(container).toMatchSnapshot()
204219
})
205220

0 commit comments

Comments
 (0)