【问题标题】:why does beforeEach not run on the 2nd describe() statement in mocha?为什么 beforeEach 不在 mocha 中的第二个 describe() 语句上运行?
【发布时间】:2012-11-12 15:41:25
【问题描述】:

第一个beforeEach 清除了用户集合...这对于第一组测试(#save() 描述)效果很好...但不适用于第二个描述(“#find()”) .

describe('User', function(){
    beforeEach(function(done){
        //clear out db
        User.remove(done);
    });

    describe('#save()', function(){

        beforeEach(function(done){
            user = new User(fakeUser);
            done();
        });

        it('should have username property', function(done){
        });


        it('should not save if username is not present', function(done){
        });
    });

    describe('#find()', function(){
        beforeEach(function(done){
            user = new User(fakeUser);
            user.save(function(err, user){
                done();
            });
        });

        it('should find user by email', function(done){
        });

        it('should find user by username', function(done){
        });
    });
});

第一个beforeEach 指的是什么?我认为它适用于每个孩子describe,但显然不是。

【问题讨论】:

    标签: unit-testing node.js mocha.js


    【解决方案1】:

    我的错,我需要添加 after 来删除收藏。

    【讨论】:

      猜你喜欢
      • 2019-03-04
      • 2017-02-28
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      • 2015-01-22
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      相关资源
      最近更新 更多