摩卡,快速testing错误 – “毕竟”钩错误 – 对象函数没有方法“closures”

我刚刚开始使用摩卡,testing一个非常基本的Express 4.0 rest API。

describe('API CALL UNIT TESTING', function(){ var app = require('../../app'); before(function(){ app.listen(3000); }); describe('GET', function(){ it('respond with json', function(done){ request(app) .get('/api/compile') .set('Accept', 'application/json') .expect('Content-Type', 'application/json') .expect(200, done) .end(function(e, res){ //console.log(res) done(); }) }) }); after(function() { app.close(); }); }); 

运行testing时,我得到以下错误:

1通过(48ms)1失败

1)API CALL UNIT TESTING“毕竟”挂钩:TypeError:对象函数(req,res,next){app.handle(req,res,next); }没有方法“closures”

任何人都可以build议是什么导致“毕竟”钩错误?

很明显,应用程序对象没有close()方法。 你实际上并没有告诉我们究竟是什么应用程序 – 但是如果我正确地记得express API,你实际上调用listen()返回的对象的close(),所以也许你可以试试:

 var server; before(function(){ server = app.listen(3000); }); .... after(function() { server.close(); });