Mongoose Post中间件测试

时间:2014-04-29 22:48:58

标签: node.js unit-testing testing express mongoose

我有两个猫鼬模特。 页面缩略图

  var Page = new Schema({
    title: { type: String, default: '', trim: true },
    url:   { type: String, default: '', trim: true },
    thumbnails: {type: Schema.ObjectId,  ref: 'Thumbnails'},
  });

  Page.post('save', function(doc) {
   if(doc.thumbnails) return;
   Thumbnail.generate(doc.url, function(err, thumb){
     doc.thumbnails = thumb;
     doc.save()
   });
  });

 var Thumbnail = new Schema({
    domain: {type: String, trim: true},
    url: {
      small: { type: String, trim: true },
      original: {type: String, trim: true }
    }
 });

 Thumbnail.statics.generate = function(doc, cb) {
   // generate site preview , save the thumbnail and call cb
 }

我正在使用mongoose post中间件来生成缩略图 如何在Post中间件中测试 Thumbnail.generate 是否被调用?

由于

0 个答案:

没有答案