茉莉花(摩卡)嵌套“它”testing

我试图testing随后的创build/删除项目(在mongoDB通过mongoose)。

创build是asynchronous的问题,它返回创build的项目在callback函数中的ID,我需要这个ID删除创build的项目,所以我尝试了摩卡(以不同的方式)下面的代码,但它没有工作。

describe('Item Model', function(){ it('should be able to create item', function(done){ var item = new Item({name: {first: "Alex"}); item.save(function(err, data){ it('should be able to deleted created item', function(done){ Item.delete({_id: data.id}, function(err, data){ done(err); }); }); }) }); }); 

这种testing可以在摩卡或茉莉花中实施吗?

我会有两个testing。 一个是testing插入和一个testing删除。

在coffeescript中应该看起来像这样

 describe 'Item model', () -> item = '' before (done) -> item = new Item {name: {first: "Alex"}} done describe 'When inserting Item', () -> before (done) -> item.save done it 'should have been insterted' -> #CHECK HERE IT IF IT IS INSERTED decribe 'when deleting', () -> before (done) -> item.save (err,data) -> return done err if err Item.delete {_id: data.id}, done it 'should have been deleted' -> #CHECK HERE IT IF IT IS Deleted 

看到这个问题: https : //github.com/visionmedia/mocha/issues/438

似乎意图是强制testing分离。 虽然不方便,可能需要更多的嘲弄,但这种行为是有用的,因为它需要较less的重新testing,并提供了一个清晰的错误图像。

即有2个testing,testingA和testingB,其中B依赖于A.

testingArest,因此B也打破。 您修复了什么是testingA,但是现在可能会惊讶地发现testingB在修复过程中破裂,或者出于不相关的原因。

当testing不依赖彼此时,您有更好的信息和更less的意外。