Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 无法访问(异步)回调函数Jest_Reactjs_Unit Testing_Jestjs_Enzyme - Fatal编程技术网

Reactjs 无法访问(异步)回调函数Jest

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'});

我试图用Jest&Ezyme测试esri承诺

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{}}似乎不在esriPromise函数中。(我也尝试过done(),但也没有成功)


任何提示都将不胜感激

尝试在addTileLayer函数中返回esriPromise

谢谢您的回复@mattphilips我尝试过,但没有成功。。。我认为,当jest称之为承诺时,它正处于等待阶段。我怎么能等到它解决了这个承诺呢?也许不是肤浅,你将不得不在这里使用mount,它将为你运行生命周期挂钩