Wie zu beheben TypeError ist nicht ein-Funktion (Test verspricht mit Scherz)

Habe ich ein bestandener test nun Dank der Antwort hier: Wie um zu testen, angekettet ist, verspricht in einem Scherz-test?

Aber ich bin noch immer ein Fehler im catch-Teil meiner Prüfung.

Ich scheine nicht in der Lage richtig zu verspotten oder Spion das Teil in die Aktionen Datei: .then(res => res.getIdToken())

TEST other, ERROR => TypeError: res.getIdToken ist nicht eine Funktion

Wie zu beheben TypeError ist nicht ein-Funktion (Test verspricht mit Scherz)

Der Test

jest.mock('services/firebase', () => new Promise(resolve => resolve({
  signInWithEmailAndPassword: () => Promise.resolve({ getIdToken: 'abc123' }),
  getIdToken: () => jest.fn(),
  signOut: () => jest.fn()
})));

describe('login actions', () => {
  let store;

  beforeEach(() => {
    store = mockStore({});
  });

  it('signIn should call firebase', () => {
    const user = {
      email: '[email protected]',
      password: 'abd123'
    };

    return store.dispatch(signIn(user.email, user.password))
      .then(() => {
        console.log('TEST signIn SUCCESS');
        expect(mockSignIn).toHaveBeenCalled();
        expect(store.getActions()).toEqual({
          type: USER_ON_LOGGED_IN
        });
      })
      .catch((err) => {
        console.log('TEST signIn ERROR =>', err);
      });
  });

Die SignIn-Aktionen/Login

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

  return firebase
    .then((auth) => {
      console.log('auth =>', auth);
      return auth.signInWithEmailAndPassword(email, password);
    })
    .catch((e) => {
      console.error('actions/Login/signIn', e);
      //Register a new user
      if (e.code === LOGIN_USER_NOT_FOUND) {
        dispatch(push(ROUTEPATH_FORBIDDEN));
        dispatch(toggleNotification(true, e.message, 'error'));
      } else {
        dispatch(displayError(true, e.message));
        setTimeout(() => {
          dispatch(displayError(false, ''));
        }, 5000);
        throw e;
      }
    })

    //I can't seem to mock this correctly
    .then(res => res.getIdToken())
    .then((idToken) => {
      if (!idToken) {
        dispatch(displayError(true, 'Sorry, there was an issue with getting your token.'));
      }

      dispatch(onCheckAuth(email));
      dispatch(push(redirectUrl));
    });
};
  • Ersetzen signInWithEmailAndPassword: () => Promise.resolve({ getIdToken: 'abc123' }) mit signInWithEmailAndPassword: () => Promise.resolve({ getIdToken: () => 'abc123' }). Es muss eine Funktion sein, meine ursprüngliche Antwort war schon wie eine Funktion 🙂 stackoverflow.com/questions/48468299/...
InformationsquelleAutor Leon Gaban | 2018-01-29
Schreibe einen Kommentar