Tunvir Rahman Tusher
Jun 16 · 1 min read
loadData = ()=>{
expect(instance.loadData).toBeDefined()//Instance is your class or component shallow instance
import axios from "axios";
jest.mock(“axios”) //Add this on top of your test file.
loadData = async ()=>{
 {data:”some data”}
axios.get.mockResolvedValue({data:”some data”});
const result = await instance.loadData()
expect(result).toEqual({data:”some data”})
axios.get.mockRejectedValue({error:”some error”});
await instance.loadData().catch(err => {
expect(err).toEqual({error:”some error”});
Tunvir Rahman Tusher

Written by

Software Developer @ Infolytx Inc. || iOS Engineer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade