我有这个行动的反应
export function fetchPosts() {
const request = axios.get(`${WORDPRESS_URL}`);
return {
type: FETCH_POSTS,
payload: request
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下如何测试axios?Jest在那里有这个用例的异步代码,他们使用模拟函数,但我不知道我是否可以用axios做到这一点?参考:https://facebook.github.io/jest/docs/tutorial-async.html
到目前为止,我已经做了这个测试,它正在返回正确的类型
it('should dispatch actions with the correct type', () => {
store.dispatch(fetchPosts());
let action = store.getActions();
expect(action[0].type).toBe(FETCH_POSTS);
});
Run Code Online (Sandbox Code Playgroud)
我不知道如何传递模拟数据并测试它返回但是,有没有人有任何想法?
先感谢您