javascript - Mongoose create test data and populate without a database connection -
i writing unit test uses mongoose model has nested object. want populate main model , referenced model without calling 'populate' , fetching database. here illustration in coffeescript
carschema = new mongoose.schema name: type: string required: true engine: type: objectid ref: 'engine' required: true auto = mongoose.model('car', carschema) engineschema = new mongoose.schema name: type:string required: true engine = mongoose.model('engine', engineschema) engine1 = new engine({name: 'test'}) car1 = new car({engine: engine1, name: 'car'}) assert.equal (car1.engine.name, 'test') #this fails
what happens car1.engine set id , not engine object. there way working?
calling setvalue
retain hydrated document:
car1.setvalue('engine', engine1)
javascript node.js unit-testing coffeescript mongoose
No comments:
Post a Comment