我正在尝试使用 Fastify 创建一个 micro-api,现在我正在测试该应用程序,但收到此错误:
Testing /allstyles
Should return all style names:
TypeError: app.address is not a function
at serverAddress (node_modules/chai-http/lib/request.js:282:18)
at new Test (node_modules/chai-http/lib/request.js:271:53)
at Object.obj.<computed> [as get] (node_modules/chai-http/lib/request.js:239:14)
at Context.<anonymous> (test/routes-chai.js:12:8)
at processImmediate (internal/timers.js:461:21)
我的应用程序文件是这样的:
const fastify = require('fastify');
var app = fastify({
logger:{level:'error',prettyPrint:true}
});
app.get('/',(req,res)=>{
console.log('Hello world');
res.code(200);
});
module.exports = app;
我的测试文件是:
var expect = require('chai').expect;
var app = require('../app/main.js');
var chaiHttp = require('chai-http');
var chai = require('chai');
chai.use(chaiHttp);
describe('Testing routes',()=>{
describe('Testing /allstyles',()=>{
it('Should return all style names',(done)=>{
chai.request(app)
.get('/')
.end((err,res)=>{
expect(res).to.have.status(200);
done();
});
});
});
});
我尝试过:
module.exports = app.listen(3000);
和
module.exports = {app}
但它总是给我返回一些错误,比如这样的一个或另一个:
TypeError: Cannot read property 'address' of undefined
有人知道我做错了什么吗?
慕斯王
qq_花开花谢_0
相关分类