No response when try test nodejs express4 route with chai-http
如果尝试运行应用程序并执行本机(POstMan)测试,则我尝试对nodejs express4路由进行运行测试,但无法获得响应-就像Sharm一样工作。
APP.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import express = require('express'); import expressValidator = require('express-validator'); import bodyParser = require('body-parser'); let app = express(); app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) app.use(expressValidator()) app.get("/", (req, res) => res.status(200).send({message:"Hello"})); app.route("/book") .get((req,res)=>{console.log(req.path);return res.status(200)}) .post((req,res)=>{return res.status( //Run app.listen(3000, function() { console.log('Listening on port '+ 3000) }) export = app; |
test.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import chai = require('chai'); import chaiHttp = require('chai-http'); import mocha = require('mocha'); let server = require('../dist/app'); let expect = chai.expect; chai.use(chaiHttp); describe('/GET', () => { it('it should not GET a book without pages field', (done) => { chai.request(server) .get('/book') .end(function(err, res) { expect(res).to.have.status(200); done(); // <= Call done to signal callback end }); }); }); |
结果是我得到错误
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure
"done()" is called; if returning a Promise, ensure it resolves.
任何回应。您可以尝试