Mocking XHR request with Jest

Cesar William Alvarenga
The Startup
Published in
2 min readJun 27, 2020

--

Icons made by Eucalyp from www.flaticon.com

In my last post, I wrote about how to mock JavaScript Fetch API on Jest using TypeScript. You can check it out here.

Now I will show how to mock an XMLHttpRequest (XHR) using the same stack: Jest and TypeScript.

Why I still use XHR instead of the Fetch API?

--

--