Mocha 的 beforeEach() 和 done() 函数不起作用



我有一个非常简单的测试套件,用摩卡写的。疯狂的是,当我"进行测试"时,我收到以下错误:

Uncaught TypeError: Object [object Object],[object Object] has no method 'done'

这是代码:

describe('Lists Endpoint (/lists)', function(){
    beforeEach(function(done){
        db.collection('lists').remove(function(err){
            db.collection('lists').insert([{name: 'LPS list', desc: 'Nice list!'}, {name: 'TLB list', desc: 'Cool listo!'}], function(err, records){
                done(); //Throws TypeError
            });            
        });        
    });

    describe('GET /lists', function(){
        it('should return an array of lists', function(done){
            request(app).get('/lists').end(function(err, res){
                res.should.have.status(200);
                res.should.be.json;
                res.body.should.be.an.Array;
                res.body.length.should.eql(2);
                res.body.
                done();
            });
        });
    });
});

我将提取这一行:

res.body.
    done();

读作res.body.done();.res.body对象上没有done方法。

最新更新