Reactjs 如何使用jest测试api调用

Reactjs 如何使用jest测试api调用,reactjs,unit-testing,jestjs,Reactjs,Unit Testing,Jestjs,我正在尝试使用jest和react测试库通过API调用测试这个react组件 callApi = () => { fetch(this.getUrl()) .then((result) => result.json()) .then((jsonResult) => { this.setState({ name: jsonResult.city.name,}) for

我正在尝试使用jest和react测试库通过API调用测试这个react组件


callApi = () => {
    fetch(this.getUrl())
    .then((result) => result.json())
        .then((jsonResult) => {
            this.setState({
                name: jsonResult.city.name,})
            for (var i = 0; i<jsonResult.list.length; i ++) {
                this.setState({
                    weather: [...this.state.weather, jsonResult.list[i].weather],
                    date: [...this.state.date, jsonResult.list[i].dt_txt],
                    clouds: [...this.state.clouds, jsonResult.list[i].clouds],
                    main: [...this.state.main, jsonResult.list[i].main],
                    wind: [...this.state.wind, jsonResult.list[i].wind],
                    rain: [...this.state.rain, jsonResult.list[i].rain],
                    snow: [...this.state.rain, jsonResult.list[i].rain]
            })}
            this.setState({
                list: jsonResult.list,
                name: jsonResult.city.name,})}
    )
}


callApi=()=>{
获取(this.getUrl())
.then((result)=>result.json())
.然后((jsonResult)=>{
这是我的国家({
名称:jsonResult.city.name,})
对于(var i=0;i