Mocking scrollHeight and getBoundingClientRect in Jest
Sep 19, 2022
I needed to create tests for a method that determined the proper height of a dynamic element, using either scrollHeight if it’s available (scrollHeight is zero for inline elements) and, if not, falling back to getBoundingClientRect()
Here’s how to mock them both:
scrollHeight:
getBoundingClientRect():