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

159
Views
How to wait to execute await statement jest

I have a component that asynchronously loads configuration from external config server and awaits for the response, i have mocked the response object with global.fetch, however my console statement is not reached, test skip executing statements after await call. Below the line after await statement is not logged. How to make jest to wait the promise is resolved?

StyleWrapper.tsx

const StyleWrapper: FC = (props) => {
  let async arrangeTiles = async() => {
    const styleConf = await StyleWrapperHelper.getStyleConfig();
    console.log(styleConf.defaultStyleName); // This line not executed during test!!!
  };
  return (
    <Context.Provider value={{ arrangeTiles }}>
      <div id="cnplStyleWrapper">{props.children}</div>
    </Context.Provider>
  );
};

StyleWrapper.test.tsx

test('Test Load style configuration', () => {

   global.fetch = jest.fn(() =>
   Promise.resolve({
            json: () => Promise.resolve({"maxNumberOfTiles":20, "defaultStyleName": "CNPLCore"}),
        })
      ) as jest.Mock;

   const styleWrapper = mount(<StyleWrapper />);
   styleWrapper.update();
      
   expect(container.html()).toMatchSnapshot();
});
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!