Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!