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