【问题标题】:Mocha.js: how to test consequent save and delete with mongooseMocha.js:如何使用猫鼬测试随后的保存和删除
【发布时间】:2012-07-12 06:37:19
【问题描述】:

测试框架:mocha 我想测试保存然后删除在 mongodb 中创建的文档(使用 mongoose)

实际执行此操作的代码:

item = new Item()
item.save(function(err, data){
   // if no errors test passed, then I need to test removing that item 
   Item.remove({_id: data.id})
})

我应该如何描述测试?

我想在输出中保存和删除单独的测试结果。

谢谢。

【问题讨论】:

    标签: node.js mongoose mocha.js


    【解决方案1】:
    var User = require('../../models/user');
    
    describe('User', function(){
      describe('#save()', function(){
        it('should save without error', function(done){
          var user = new User({        username    : 'Luna'
            , email     : 'luna@me.name'
            , password  : 'asdf123'
          });
          user.save(function(err){
            if (err) throw err;
            done();
          });
        })
      })
    })
    

    【讨论】:

    • 这并没有说明删除文档,或者如何在单独的测试中进行。
    猜你喜欢
    • 2021-07-05
    • 2014-08-03
    • 2018-03-04
    • 2019-07-04
    • 2015-04-10
    • 2012-11-11
    • 2017-09-07
    • 2021-07-28
    • 2016-01-01
    相关资源
    最近更新 更多