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

241
Vistas
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 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