Unit Test Async Action Creator for Failed Promise
$10-30 USD
货到付款
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.
项目ID: #16898548