koa-lite/test/response/header.js
Ilkka Oksanen 91c403a541 response: don't access res._headers directly when helpers exist
res._headers is considered internal to node itself. Its value will
change in a backwards incompatible way in the future node releases.

Use the documented helper functions instead when they are available.
2017-02-25 21:12:18 -06:00

30 lines
740 B
JavaScript

'use strict';
var response = require('../context').response;
describe('res.header', function(){
it('should return the response header object', function(){
var res = response();
res.set('X-Foo', 'bar');
res.header.should.eql({ 'x-foo': 'bar' });
})
it('should use res.getHeaders helper when it is available', function(){
var res = response(null, {
_headers: {},
getHeaders: function(){
return { 'x-foo': 'baz' }
}
});
res.header.should.eql({ 'x-foo': 'baz' });
})
describe('when res._headers not present', function (){
it('should return empty object', function (){
var res = response();
res.res._headers = null;
res.header.should.eql({});
})
})
})