I want to save two Mongoose objects in my mocha test - and be notified when both have succeeded. I am using the asyncjs library to achieve this.
beforeEach (done) ->
obj1 = new Person({ name: 'Jon' })
obj2 = new Person({ name: 'Dan' })
console.log obj1 # ... { name: 'Jon', _id: 4534534543512 }
async.list([
obj1.save
obj2.save
]).call().end( (err, res) ->
return done(err) if err
done()
)
You can see that obj1 is being set to a MongoDB document in the console.log - but when I want to persist them to the db using the save function, I get the following error when trying to execute this:
TypeError: Cannot read property 'save' of undefined
If I were to replace the two functions in the async.list with say
console.log
console.log
The code executes fine ... Also, if I were to save the two objects outside the async.list function like so
obj1.save()
obj2.save()
It too executes fine with no errors.
I am stumped.