Reactjs 无法访问(异步)回调函数Jest
我试图用Jest&Ezyme测试esri承诺Reactjs 无法访问(异步)回调函数Jest,reactjs,unit-testing,jestjs,enzyme,Reactjs,Unit Testing,Jestjs,Enzyme,我试图用Jest&Ezyme测试esri承诺 import { esriPromise } from 'react-arcgis'; componentWillMount(){ this.setState({name: 'JAKE'}); this.addTileLayer(); }; addTileLayer(ext, url) { this.setState({name: 'Amber'});
import { esriPromise } from 'react-arcgis';
componentWillMount(){
this.setState({name: 'JAKE'});
this.addTileLayer();
};
addTileLayer(ext, url) {
this.setState({name: 'Amber'});
let promise = esriPromise(['esri/layers/TileLayer']).then(([TileLayer]) => {
this.setState({name: 'THISONE'});
let tileLayer = new TileLayer();
this.setState({
layers: [...this.state.layers, tileLayer]
})
}).catch((err) => console.error(err));
this.setState({prmoise: promise})
};
在我的测试中
test('Promise states check', async () => {
const map = shallow(<Map />)
await map.instance().componentWillMount();
console.log(map.state());
});
test('promission states check',async()=>{
常量映射=浅()
等待map.instance().componentWillMount();
console.log(map.state());
});
但是它总是打印,promise:promise{任何提示都将不胜感激 尝试在addTileLayer函数中返回esriPromise谢谢您的回复@mattphilips我尝试过,但没有成功。。。我认为,当jest称之为承诺时,它正处于等待阶段。我怎么能等到它解决了这个承诺呢?也许不是肤浅,你将不得不在这里使用mount,它将为你运行生命周期挂钩