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

156
Views
how to obtain return value associated with a promise

I have a javascript application with a file called index.js as follows:

module.exports.func = async (obj) => {
    return {
      statusCode: 200,
      body: JSON.stringify({
        message: 'Success!',
        input: obj,
      }),
    };
};

To test this, I have written another file called index.test.js, which has the following code (it's not yet complete but has the code to illustrate my problem):

const exportedModule = require('./index');

test('Successfully execute func when empty object passed', () => {
  const obj = {};
  const expectedReturn = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Success!',
      input: obj,
    }),
  };
  const actualReturn = exportedModule.func(obj);
  console.log(actualReturn);
  expect(actualReturn).toBe(expectedReturn);
});

When this code runs, the console.log(actualReturn) function is outputting Promise { <pending> }. Normally I would address this by adding an await before exportedModule.func, but for some reason this does not work and an error is thrown saying exportedModule.func is not asynchronous (even though I have used async when writing the function). Would anyone know of the correct way to get the actual returned value of the fucntion, and not a promise? Or is there something wrong with the way I'm getting the func function that's causing it to not be recognised as asynchronous?

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!