reactjs - 如何测试 Firebase signInWithEmailAndPassword?
问题描述
我想测试我的操作,看看是否调用了 dispatch 和 history spy。但它每次都会在 catch ( dispatch GET_ERRORS ) 中结束。
它给了我这个错误:
code: 'auth/network-request-failed',
message: 'A network error (such as timeout, interrupted connection or unreachable host) has occurred.'
行动:
export const startLogin = ( { email, password } ) => {
return ( dispatch ) => {
dispatch( setAuthLoading() );
return firebase
.auth()
.signInWithEmailAndPassword( email, password )
.then( ( user ) => {
const userData = {
uid: user.uid,
name: user.displayName,
email: user.email
}
// This is what I want to test. If dispatch, history was called
dispatch( setCurrentUser( userData ) );
history.push( '/' );
})
.catch( ( err ) => {
// It ends up everytime here, why?
dispatch({
type: GET_ERRORS,
payload: err
});
dispatch( clearAuthLoading() );
});
};
};
测试:
test( 'should start login with correct data', ( done ) => {
const pushSpy = jest.spyOn( history, 'push' );
const store = createMockStore({});
const name = 'Josh';
const loginData = {
email: 'test@gmail.com',
password: '123456password'
};
store.dispatch( startLogin( loginData ) ).then(() => {
const actions = store.getActions();
expect( actions[0] ).toEqual({
type: SET_CURRENT_USER,
user: {
name,
email: loginData,
psasword: loginData.password
}
});
expect( pushSpy ).toHaveBeenLastCalledWith( '/' );
done();
});
});
可能是firebase安全问题吗?我尝试了一切,但最终还是被抓住了。
谢谢
解决方案
推荐阅读
- react-native - 如何为平面列表中的三个项目创建唯一的密钥提取器
- android - 我可以在android studio中同时打开第二个模拟器吗
- android - VerifyError 仅在旧设备上发生
- javascript - 为什么在 navigator.geolocation.getCurrentPosition() 为其分配值并返回它之后我无法访问我的对象中的值?
- typescript - 获取 Typescript 接口属性类型,仅给定属性名称
- typescript - 根据推断的参数类型区分函数返回类型
- java - org.springframework.dao.DataAccessResourceFailureException
- javascript - 检测正在滚动的元素
- c++ - 将此 lambda 表达式传递给 `unique_ptr` 是否可以终身使用?
- r - 闪亮的应用程序不起作用,似乎根本不读取服务器端代码