Home > Back-end >  How to test which element has focus with React and testing-library
How to test which element has focus with React and testing-library

Time:10-20

I am working on a react app using mainly functional components. This is all tested with the react - testing library. I would like to test the focus of some elements to show that after some interactions certain elements gain focus but I cant see anything to support this. Is it possible ?

thanks

CodePudding user response:

yes, it's possible by using jest-dom's toHaveFocus matcher.

CodePudding user response:

use document.activeElement is the answer

  • Related