testing状态码以外的响应标题字段时遇到困难

我正在使用Express框架。 其任务是从数据库中检索一个集合,并将自定义的消息插入到返回给客户端的响应头文件中(下面显示的Node.js代码工作正常,我可以在返回的头文件中看到我的自定义消息):

if (req.accepts('json')) { **res.header('Warning', 'my_customized_message');** res.header('Content-Type', 'application/json'); res.send(res.locals.items, 200); } 

现在,我尝试使用“mocha”来使用MOCHA对新添加的代码进行unit testing:

 request = require('request'); should = require('should'); describe('GET /core/dbq/534e930204dd311822ec1c9d', function() { this.timeout(15000); it ('Check header message', function(done) { request.get('http://localhost:3001/ecrud/v1/core/dbq/534e930204dd311822ec1c9d', function(err, response, header) { response.statusCode.should.equal(200); response.warning.should.equal('my_customized_message'); // Uncaught TypeError: Cannot read property 'should' of undefined done(); } ) } ) } ) 

如果我只testingresponse.statusCode,没有问题。 MOCHAtesting成功通过。 但是,如果我testingresponse.warning,我得到一个错误,说属性'应该'没有定义(我运行npm应该–save-dev)。 看起来“警告”不被认为是“回应”的一个领域。 但是,“警告”是响应领域之一。

如果我尝试testingresponse.contentType,则会发生同样的错误。 我以为“内容types”是一个非常知名的响应标题字段。 无论如何,我真正感兴趣的是testing“警告”标题。 请帮忙。 谢谢。

我想你想这个( response是一个http.IncomingMessage ):

 response.headers.warning.should.equal('my_customized_message');