I did the test below for a seed that needs to get data from the model User. I think my problem here is that testFunction is returning name before it's value is updated within the .then().
I clearly don't understand how the flow is working here. Anybody has an idea about why is this happening and how could I solve it? Thank in advance ;)
const testFunction = () => {
let name = undefined
User.find()
.then(result => name = result[0].username)
.catch(err => console.log(err))
return name }