testing-library / user-event

🐕 Simulate user events
https://testing-library.com/user-event
MIT License
2.14k stars 242 forks source link

feat: add option to set element class on hover #1212

Open rChaoz opened 2 months ago

rChaoz commented 2 months ago

What:

Add option to set a class on target element on hover. Useful for testing hover states either by manually adding .my-hover-class on top of :hover in CSS or with a plugin such as the one for PostCSS or Storybook.

Why:

Allow testing of CSS hover states using userEvent.hover / userEvent.unhover or other commands that move the mouse.

How:

Add a new config option hoverClass (string) which defaults to null. When set (non-null), target.classList.add(hoverClass) is called whenever mouseenter is emitted and target.classList.remove(hoverClass) whenever mouseleave is emitted.

Checklist:

codesandbox-ci[bot] commented 2 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.