Cannot read property 'baseURL' of undefined in JEST while mocking axios
<p>I tried ajax call using AXIOS in React Component as below, </p>

<pre><code>    let that = this;
    this.serverRequest = axios({
        url: '/login',
        method: 'post',
        data: JSON.stringify({ userName: "testing", passWord: "passWord" }),
        headers: {
            "Content-Type": 'application/json; charset=utf-8'
        }
    }).then(function (successData) {                    
            localStorage.setItem('userData', JSON.stringify(successData.data));
            this.setState({
                successMsge: "Valid credentials"
            });
        }).catch(function(errorData){                   
            this.setState({
                errorMessage: errorData.data.message,
                errorDisplay: true
            });
        }.bind(that));
</code></pre>

<p>React component works perfectly, when i try to mock the above component in JEST an error is been displayed.</p>

<p>i have attached the JEST code below,</p>

<pre><code>expect(axios).toBeCalledWith({
    type: 'POST',
    baseURL: '/login',
    data: JSON.stringify(dataParams),
    headers: {
        "Content-Type": 'application/json; charset=utf-8'
    }
});
</code></pre>

<p>when i run npm jest i get the below error for the above component</p>

<pre><code>  - TypeError: Cannot read property 'baseURL' of undefined
        at Axios.request (node_modules\axios\lib\axios.js:32:13)
</code></pre>

<p>can anyone help me resolving the above error in JEST</p>