Skip to content Skip to sidebar Skip to footer

Can't Call .then When Mocking Axios Call Inside Componentdidmount

I'm trying to unit test componentDidMount while mocking an Axios call. // src/App.tsx import axios_with_baseUrl from './axios-instance-with-baseUrl'; ... public componentDidMount

Solution 1:

Just add return before axios_with_base_url to make promise

public componentDidMount() {
    return axios_with_baseUrl.get('/data.json')
       .then(resp => this.setState({ stuff }));
}

Post a Comment for "Can't Call .then When Mocking Axios Call Inside Componentdidmount"