Typescript, Jest and Axios
I found different posts that tell you how to mock Axios using Jest & Typescript. The only difference in this post is that, when I use Axios, I like to use it as a function rather than calling axios.get or axios.post. Imagine you have this Axios request that you want to mock in your tests: //src/index.ts import axios from "axios"; export interface Post { userId: number; id: number; title: string; body: string; } const DummyRequest = (id: number): Promise<Post> => { return axios({ method: "GET", url: `https://jsonplaceholder.typicode.com/posts/${id}`, }).then((response) => { return { ...response.data }; }); }; export default DummyRequest; Install jest and jest-ts and initialize jest-ts ...