title: Jest/Enzyme Unit Test on Axios Requests in ComponentDidMount()
body: <p>I am trying to perform some unit testing on my existing react application with Jest and Enzyme. I am totally new to this stuff and accurately I do not know how to approach such test scenarios. I know that to test API request calls I have to perform some &quot;mocking&quot;, but how should I write the test for that?. What will be the steps that needs to be followed?</p>
  <p>Following is the code snippet I am looking to test.</p>
  <p>Home.js</p>
  <pre><code>import React,{Component} from 'react'
  import axios from 'axios';
  import {Link} from 'react-router-dom';
  import FacilityModal from '../Table/FacilityModal';
  
  class Home extends Component {
    state = {
      cities:[],
      name:''
    }
   
    componentDidMount() {
      axios.get('/cities').then(res =&gt; {
        this.setState({cities:res.data})
        console.log(&quot;Oza&quot; + JSON.stringify(res))
      });
      console.log(this.state.cities)
    }
   
    render() {
      let postList = this.state.cities.map(city =&gt; {
        return(
          &lt;div key = {city.id}&gt;
            &lt;p&gt;
              &lt;Link to = {'/'+city.id}&gt;{city.name}&lt;/Link&gt;
            &lt;/p&gt;
          &lt;/div&gt;
        )
      })
      return(
        &lt;div className = 'align'&gt;All Facilities (NCAL)
          &lt;div className=&quot;hr-sect&quot;&gt;OR&lt;/div&gt;
          &lt;div className = 'Modal'&gt;
            {postList}
          &lt;/div&gt;
          &lt;FacilityModal cityname = {this.props} /&gt;
        &lt;/div&gt;
      )
    }
  }
  </code></pre>