相关疑难解决方法(0)

如何测试仅调度其他操作的Redux操作创建者

我在测试一个动作创建器时遇到了麻烦,该动作创建器只是遍历传递给它的数组,并为该数组中的每个项目调度一个动作.这很简单,我似乎无法弄明白.这是动作创建者:

export const fetchAllItems = (topicIds)=>{
  return (dispatch)=>{
    topicIds.forEach((topicId)=>{
      dispatch(fetchItems(topicId));
    });
  };
};
Run Code Online (Sandbox Code Playgroud)

以下是我试图测试的方法:

describe('fetchAllItems', ()=>{
  it('should dispatch fetchItems actions for each topic id passed to it', ()=>{
    const store = mockStore({});
    return store.dispatch(fetchAllItems(['1']))
      .then(()=>{
        const actions = store.getActions();
        console.log(actions);
        //expect... I can figure this out once `actions` returns...
      });
  });
});
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:TypeError: Cannot read property 'then' of undefined.

javascript reactjs redux redux-thunk

4
推荐指数
1
解决办法
2581
查看次数

如何测试Redux-Thunk使用Unit Test Jest的动作?

我是一个新的单元测试Redux-thunk使用Jest的Action .

以下是代码:

export const functionA = (a,b) => (dispatch) =>{
    dispatch ({type: CONSTANT_A, payload: a});
    dispatch ({type: CONSTANT_B, payload: b});
} 
Run Code Online (Sandbox Code Playgroud)

如何测试功能使用Unit-Test Jest?任何人都可以帮助我^^.预先感谢 :)

unit-testing jestjs redux redux-thunk

4
推荐指数
1
解决办法
3717
查看次数

标签 统计

redux ×2

redux-thunk ×2

javascript ×1

jestjs ×1

reactjs ×1

unit-testing ×1