how to match a returned Promise in using Jest with redux action

杀马特。学长 韩版系。学妹 提交于 2019-12-02 08:48:00

fetchContentVideoList doesn't wait for the promise to be resolved or rejected, so the payload becomes the unresolved promise.

One way to fix this would be to use the async/await method:

export async function fetchContentVideoList(page, size, where, sort) {
    const request = await axios.get('url');
    return {
        type: FETCH_CONTENT_VIDEO_LIST,
        payload: request
    };
}

See async docs on MDN for more information.

Edit for Question Update

This change turns the action into an asynchronous action, which means that it needs to be handled in a slightly different way. Making the expections after the promise has resolved (as you are doing) is one good way to test the action.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!