代码之家  ›  专栏  ›  技术社区  ›  user4445419

运行测试未按预期运行

  •  0
  • user4445419  · 技术社区  · 10 年前

    我运行了以下测试,它不会停止快速路由器的操作 这个网址正是我放在邮差里的网址,你知道吗?

    描述(“测试”,函数(){

    it('Should Run///',
        function (done) {
    
            supertest(app)
                .post('http://localhost:3002//save/test1/test2/test3')
                .expect(200)
                .end(function (err, res) {
                    res.status.should.equal(200);
                    done();
                });
    
        });
    
        in the following code its not stopping in the post  (console.log...)what am I missing here?
    
        module.exports = function (app, express) {
    
    var appRouter = express.Router();
    app.use(appRouter);
    //Route Application Requests
    appRouter.route('*')
        .post(function (req, res) {
            console.log("test");
        })
    
    1 回复  |  直到 10 年前
        1
  •  0
  •   robertklep    10 年前

    您没有在路由处理程序中发送响应:

    appRouter.route('*')
        .post(function (req, res) {
            console.log("test");
            return res.sendStatus(200); // <-- actually send back a response!
        });
    

    此外,从您的代码中可以看出,您正在向Supertest传递一个Express应用程序,而不是服务器,在这种情况下,您可能需要使用以下命令:

    .post('/save/test1/test2/test3')
    

    (而不是完整的url)