Unit Test Async Action Creator for Failed Promise

已关闭 已发布的 5 年前 货到付款
已关闭 货到付款

I'm working on a test case where I'm trying to test async action creator for a failed response. But the error is a promise and when the unit test is running the error promise is not resolving and the test is failing.

eg:

// [login to view URL]

export const fetchData = () => {

return (dispatch) => {

return fetchJSON(URL).then((data) => {

dispatch(successAction(FETCH_SUCCESS, data));

}.catch((err) => {

[login to view URL]().then((value)) => {

dispatch(failedAction(FETCH_FAIL, err));

});

});

};

};

[login to view URL]

it("fetchData action", async() =>{

const fetchSpy = [login to view URL](jQuery, "get").reject({status: 400});

const dispatchSpy = [login to view URL]();

await fetchData()(dispatchSpy);

[login to view URL]();

[login to view URL](fetchSpy);

}

[login to view URL] is undefined as it is not resolving before the unit test case finishes.

JavaScript React.js

项目ID: #16898548

关于项目

远程项目 活跃的5 年前