Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
How to mock an async redux action in jest?

I'm using jest in my expo project for unit testing. I am new to jest I don't know how to use mock functions to test my redux actions.Following is my action for SignIn.

authActions.ts

..
import Api, {
  SubscriptionPreference,
} from "@myPackage/api";
...
    export const signIn =
      ({ email, phoneNumber, password }) =>
      async (dispatch) => {
        console.log("DATA")
        dispatch({ type: types.STATE_LOADING });
      try {
           const result = (
            await Api.accounts.accountsLogin({
              email,
              phoneNumber,
              password,
            })
          ).data;    
     
          if (!result.success) {
            throw new Error(i18n.t("signin_incorrectUsername"));
          }
    
          await SecureStore.setItemAsync("authtoken", result.token);
          dispatch(loadAuth());
        } catch (e) {
          const errorMessage = e.error?.message || e.message;
          Alert.alert(errorMessage);
          dispatch({
            type: types.AUTH_ERROR,
            payload: errorMessage,
          });
        }
      };

The Api is being called from my custom package.So I am not sure how to write a test suite for my signIn action. I have gone through several documentation but couldn't find a proper one for my case. If anybody knows the answer please help. Any help would be really appreciable. Thank you

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda