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

240
Visualizações
Test if a function is called after a promise in React

I'm learning to test React applications, right now I have a function that will run after a promise (innerFunction) in my App.jsx, like this:

function App() {
  const [isReady, setIsReady] = useState(false);
  const innerFunction = wrapperFunction();

  useEffect(() => {
    thirdPartyPkg.onReady().then(() => innerFunction(isReady, setIsReady));
  }, []);

  // ...
}

This is what the code on wrapperFunction.js looks like:

export function wrapperFunction() {
  return function innerFunction(isReady, setIsReady) {
    if (isReady) {
      setIsReady(true);
    }
  };
}

And this is my App.test.jsx:

import * as Function from "./utils/wrapperFunction";

describe("testing App", () => {
  it("should run innerFunction once after promise", () => {
    const inner = jest.spyOn(Function, "wrapperFunction");

    expect(inner).toBeCalledTimes(1);
  });
});

I'm guessing that I need to wait to the promise to resolve, but I'm kind of blocked, do you guys have any suggestion to test if the innerFunction is called?

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