I got a very simple react component with following functionallity:
componentDidMount() {
window.scrollTo(0, 0)
}
It seems that you cannot do something like
window.scrollTo = jest.fn()
to spy on scrollTo
function.
Therefor, I want to know what is the best way to spy on this function and assert that it has been used in my tests.
Thanks
In jest the global name space must be accessed by global
not window
.
global.scrollTo = jest.fn()