相关疑难解决方法(0)

如何在开玩笑测试中测试链式承诺?

下面我对我的登录操作进行了测试.我正在嘲笑firebase函数,并想测试是否调用了signIn/signOut函数.

测试通过然而我没有看到我的第二个控制台日志.这是哪一行console.log('store ==>', store);.

it('signIn should call firebase', () => {
  const user = {
    email: 'first.last@yum.com',
    password: 'abd123'
  };

  console.log('111');
  return store.dispatch(signIn(user.email, user.password)).then(() => {
    console.log('222'); // does not reach
    expect(mockFirebaseService).toHaveBeenCalled();
  });
  console.log('333');
});
Run Code Online (Sandbox Code Playgroud)

●登录操作> signIn应该调用firebase

TypeError:auth.signInWithEmailAndPassword不是函数

在此输入图像描述

正在测试的行动

// Sign in action
export const signIn = (email, password, redirectUrl = ROUTEPATH_DEFAULT_PAGE) => (dispatch) => {
  dispatch({ type: USER_LOGIN_PENDING });

  return firebase
    .then(auth => auth.signInWithEmailAndPassword(email, password))
    .catch((e) => {
      console.error('actions/Login/signIn', e);
      // Register a new user
      if (e.code …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing reactjs jestjs

3
推荐指数
1
解决办法
1984
查看次数

标签 统计

javascript ×1

jestjs ×1

reactjs ×1

unit-testing ×1