Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testing and minor refactorings #1171

Merged
merged 18 commits into from
Feb 18, 2024
Merged

Fix testing and minor refactorings #1171

merged 18 commits into from
Feb 18, 2024

Conversation

gabrieljablonski
Copy link
Member

Closes #1080.

Might close other test related issues. Will have to check.

Comment on lines 1 to 19
import type { IComputePositions } from './compute-tooltip-position-types'
import computeTooltipPosition from './compute-tooltip-position'
import cssSupports from './css-supports'
import cssTimeToMs from './css-time-to-ms'
import debounce from './debounce'
import getScrollParent from './get-scroll-parent'
import useIsomorphicLayoutEffect from './use-isomorphic-layout-effect'

export type { IComputePositions }
export {
computeTooltipPosition,
cssSupports,
cssTimeToMs,
debounce,
getScrollParent,
useIsomorphicLayoutEffect,
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had some inconsistent exports here. All util functions are now default exported, and available with named export from utils/index.ts.

@gabrieljablonski
Copy link
Member Author

For future reference, when testing the tooltip NOT to be on screen, we recommend the following (using @testing-library/react):

await waitFor(() => {
  expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
})

When getting a reference to the tooltip, we recommend this:

const tooltip = await screen.findByRole('tooltip')
expect(tooltip).toHaveAttribute('style')

Waiting for the tooltip to have the react-tooltip__show (or react-tooltip__closing) class is often not necessary, but may be useful when testing both opening and closing the tooltip on the same spec.

await waitFor(() => {
  // also useful with `react-tooltip__closing`
  expect(screen.queryByRole('tooltip')).toHaveClass('react-tooltip__show')
})

@gabrieljablonski gabrieljablonski merged commit 7e1a554 into master Feb 18, 2024
5 checks passed
@gabrieljablonski gabrieljablonski deleted the test/fix-testing branch February 18, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Test 'tooltip with delay show' inconsistent snapshot
2 participants