Use Promise.all to Transform Array of Promises into One

beforeEach(async () => {
await Blog.deleteMany({})
const blogObjects = helper.initialBlogs
.map(blog => new Blog(blog))
const promiseArray = blogObjects.map(blog => blog.save())
await Promise.all(promiseArray)
})
  • const results = await Promise.all(promiseArray) will return an array of resolved values from each promise in the same order the promises.
  • executes promises in parallel

Source -> MDN Web Docs: Promise.all()