I have a function something like that:
async function example(){
let data = await another_function();
var ws = fs.createWriteStream('path');
let jsonData = [{'id':'1234', 'name': 'Alex'}];
fastcsv
.write(jsonData, { headers: true })
.on("finish", function() {
console.log('success');
})
.pipe(ws)
return true;
}
But when I run a test using jest I get an error:
Cannot log after tests are done. Did you forget to wait for something async in your test? Attempted to log "success".
Test function looks like this:
test('success', async() => {
var expected = true;
var result = await example();
assert.equal(result, expected);
})
How can I change example function to run it synchronously? And await till I get 'true' as return data from this function