How to mock window object in Jest with deep-rooted methods called

Ivy Lyu
2 min readJul 4, 2021

Recently I have some unit tests need to mock window object and implement some methods of it, and it is a deep-rooted object which is hard to mock but luckily I found some useful document and winged a bit and then boom! Happy Ending!

Photo by Ryunosuke Kikuno on Unsplash

I was implementing a payment solution where it requires a Flex object in the window object and Jest gives an official…

--

--