摩卡testing:“TypeError:undefined不是一个函数”在Test.serverAddress

我有以下testing:

describe('Testing the GET methods', function() { it('Should be able to get the list of articles', function(done) { // Create a SuperTest request request(app).get('/api/articles/') .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(200) .end(function(err, res) { res.body.should.be.an.Array.and.have.lengthOf(1); res.body[0].should.have.property('title', article.title); res.body[0].should.have.property('content', article.content); done(); }); }); it('Should be able to get the specific article', function(done) { // Create a SuperTest request request(app).get('/api/articles/' + article.id) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(200) .end(function(err, res) { res.body.should.be.an.Object.and.have.property('title', article.title); res.body.should.have.property('content', article.content); done(); }); }); }); 

其中产生以下错误: 在这里输入图像说明

任何想法可能是什么问题? 我有所有的依赖项检查和安装,并要求。

编辑:

发生这种情况的原因是这样的: https : //github.com/Oreqizer/mean-book/blob/master/server.js – 第11至18行。

我的testing开始之前,应用程序连接到数据库。 我通过console.logging'app'注意到了这一点,并注意到在第一次testing期间Server running at http://localhost:3000/在不同的时间被logging。

在运行testing之前,如何让摩卡等待应用程序的定义?

好,所以这样下去:

更新版本的“mongoose”会导致在我做var app = express(db);之前没有定义的“db”连接var app = express(db); 。 但是,如果我添加的代码:

 db.connection.on('connected', callback); 

在callback中我定义的app ,在没有定义app的情况下执行testing。

我真的不知道如何解决这个问题,除了有两个不同的版本,一个用于testing环境,一个用于开发/生产。