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

时间:2018-03-07 00:46:35

标签: reactjs unit-testing jestjs enzyme

我试图用Jest& amp测试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());
 });

但它始终打印,承诺:承诺{&lt;待定&gt;似乎它不会进入esriPromise函数。 (我也尝试过done(),但也没有成功)

任何提示都将不胜感激!

1 个答案:

答案 0 :(得分:1)

尝试在addTileLayer函数中返回esriPromise