简体   繁体   中英

Mocha's beforeEach() and done() function not working

I have a very simple test suite written in mocha. The crazy thing is when I 'make test', I get the following error:

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

Here is the code:

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();
            });
        });
    });
});

I'll extract this line:

res.body.
    done();

Which is read as res.body.done(); . There's no done method on res.body object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM