Skip to content

Instantly share code, notes, and snippets.

@jimkeller
Last active September 19, 2022 03:51
Show Gist options
  • Save jimkeller/9a3946f3ca7841625d3d9167a0ed72f8 to your computer and use it in GitHub Desktop.
Save jimkeller/9a3946f3ca7841625d3d9167a0ed72f8 to your computer and use it in GitHub Desktop.
mocking getBoundingClientRect in jest
const my_element = document.getElementById('#my-element)
jest.spyOn(my_element, "getBoundingClientRect").mockImplementation(
() => {
return new DOMRect(0, 0, 100, 500) //100px wide, 500px tall
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment