reactjstesting-library

How to test which element has focus with React and testing-library


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


Solution

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