Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda