Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hover): Add hover API (fixes #254)
- Loading branch information
1 parent
dbdefef
commit c286e4d
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
import {render, screen} from '@testing-library/react' | ||
import userEvent from '..' | ||
import {setup} from './helpers/utils' | ||
|
||
test('hover', () => { | ||
const {element, getEventCalls} = setup(<button />) | ||
|
||
userEvent.hover(element) | ||
expect(getEventCalls()).toMatchInlineSnapshot(` | ||
mouseenter: Left (0) | ||
mouseover: Left (0) | ||
mousemove: Left (0) | ||
mouseout: Left (0) | ||
mouseleave: Left (0) | ||
`) | ||
}) | ||
|
||
test('hover should fire events', () => { | ||
const handler = jest.fn() | ||
render( | ||
// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events | ||
<button | ||
data-testid="button" | ||
onMouseEnter={handler} | ||
onMouseOver={handler} | ||
onMouseMove={handler} | ||
onMouseOut={handler} | ||
onMouseLeave={handler} | ||
/>, | ||
) | ||
|
||
userEvent.hover(screen.getByTestId('button')) | ||
expect(handler).toHaveBeenCalledTimes(5) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters