1
我有以下测试:摩卡测试:“类型错误:未定义不是一个函数”在Test.serverAddress
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
我的测试开始前,应用程序连接到数据库。我通过console.logging'app'注意到了这一点,并注意到在第一次测试期间的不同时间会记录 Server running at http://localhost:3000/
。
在运行测试之前,我如何让摩卡等待应用程序的定义?
你在哪里定义了'app' –
https://github.com/Oreqizer/mean-book/blob/master/app/tests/articles.server.controller.tests.js这里。您可以检查整个源代码是否有帮助 – Idefixx
当您查看调用堆栈中提到的第一个文件(结束于supertest \ lib'test.js)的第55行时,是否显示:var add = app.address() ;'? – regular