so I have two js files file1.js
const { expect } = require("chai");
const { createEnrollment } = require("../utils/file2")
describe('create enrollment', function () {
it('enroll the user into the system', async function () {
var x = createEnrollment(inputParams)
console.log(x)
})
File2.js
const fetch = require('node-fetch')
async function createEnrollment(params) {
fetch('URL').then(function (response) {
response.json().then(function (text) {
var val = text;
console.log("VALUE " + val.userId)
return text;
});
module.exports = { createEnrollment }
But when I run this code console.log(x) is undefined and is running before createEnrollment is complete. I made the function async but still the value returning is undefined.