我在测试一个动作创建器时遇到了麻烦,该动作创建器只是遍历传递给它的数组,并为该数组中的每个项目调度一个动作.这很简单,我似乎无法弄明白.这是动作创建者:
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
.
我是一个新的单元测试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?任何人都可以帮助我^^.预先感谢 :)