小编use*_*014的帖子

supertest test express中间件

发现以下关于如何在Express中测试中间件的提示:
https://github.com/visionmedia/express/blob/master/test/req.xhr.js
我想知道为什么我的测试总是通过.直到我注意到,当我从快递复制测试时,他们表现得一样.我试过拧紧它们但是它们不断传递:https: //github.com/visionmedia/express/blob/master/test/req.xhr.js

我在这里缺少什么?

it('should return true when X-Requested-With is xmlhttprequest', function(done){
  var app = express();

  app.use(function(req, res){
    req.xhr.should.be.false; //set to false, to fail the test but it still passes
    res.end();
  });

  request(app)
  .get('/')
  .set('X-Requested-With', 'xmlhttprequest')
  .end(function(res){
    done();
  })
})
Run Code Online (Sandbox Code Playgroud)

javascript testing node.js express supertest

6
推荐指数
1
解决办法
1846
查看次数

标签 统计

express ×1

javascript ×1

node.js ×1

supertest ×1

testing ×1