This is my main component. When I click on the button popover shows notifications. Let's see...
const NotificationDropdown = ({ unread = 0 }) => (
<PopupState variant="popover">
{popupState => {
const { isOpen } = popupState
return (
<>
<Button open={isOpen} unread={unread} {...bindTrigger(popupState)} />
<Popover
{...bindPopover(popupState)}
anchorOrigin={makeOrigin('bottom', 'center')}
transformOrigin={makeOrigin('top', 'center')}
>
<Notifications data-testid="notification-content" />
</Popover>
</>
)
}}
</PopupState>
)
I tried write tests for that:
const Component = ({ unread }) => (
<>
<NotificationDropdown unread={unread} />
<span data-testid="somewhere">For click action</span>
</>
)
it('should be closed after click somewhere', async () => {
render(Component)
clickElementByTestId('notification-btn')
const contentNotification = screen.queryByTestId('notification-content')
expect(contentNotification).toBeInTheDocument() // Good
clickElementByTestId('notification-btn')
expect(contentNotification).not.toBeInTheDocument() // Fail! The document still exits.
})
Maybe it's an issue with animation (during the assertion component it's in the animation process). But I tried delay assertion for example:
jest.advanceTimersByTime(2000)
await waitFor(() => {
expect(contentNotification).not.toBeInTheDocument()
})
But I got the same results.
How to fix it?
This is my main component. When I click on the button popover shows notifications. Let's see...
I tried write tests for that:
Maybe it's an issue with animation (during the assertion component it's in the animation process). But I tried delay assertion for example:
But I got the same results.
How to fix it?