【发布时间】:2018-11-18 09:07:34
【问题描述】:
我正在使用 React、Redux 和 Firebase 开发 POC。我目前正在研究如何测试动作创建者。我遵循了这个 - https://redux.js.org/recipes/writing-tests#async-action-creators 指南,到目前为止它很有帮助。但是,作为一个简单的示例,我想测试在成功通过 Firebase 进行身份验证后分派了一个动作,就像这样 -
动作创建者
export const authenticate = (username, password) => {
return dispatch => {
firebase.auth().signInWithEmailAndPassword(username, password)
.then(() => {
dispatch(authenticationSuccessful())
})
.catch(() => {
});
}
};
动作
const authenticationSuccessful = () => {
return {
type: actionTypes.AUTHENTICATION_SUCCESSFUL
};
};
对于我开玩笑的事情的测试方面,redux-mock-store 和期望。我研究了其他人在这种情况下使用了什么,但我还没有找到明确的答案,我也看过https://www.npmjs.com/package/firebase-mock,但我不知道这是否是社区中的热门选择。
非常感谢您提前提供的任何帮助!
【问题讨论】:
标签: reactjs unit-testing firebase redux jestjs