2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-12 04:59:30 +00:00
|
|
|
const response = require('../helpers/context').response;
|
2015-10-05 18:23:47 +00:00
|
|
|
const should = require('should');
|
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
describe('res.length', function(){
|
|
|
|
describe('when Content-Length is defined', function(){
|
|
|
|
it('should return a number', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = response();
|
2013-11-13 17:01:15 +00:00
|
|
|
res.header['content-length'] = '120';
|
|
|
|
res.length.should.equal(120);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('res.length', function(){
|
|
|
|
describe('when Content-Length is defined', function(){
|
|
|
|
it('should return a number', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = response();
|
2013-11-13 17:01:15 +00:00
|
|
|
res.set('Content-Length', '1024');
|
|
|
|
res.length.should.equal(1024);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when Content-Length is not defined', function(){
|
|
|
|
describe('and a .body is set', function(){
|
|
|
|
it('should return a number', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = response();
|
2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
res.body = 'foo';
|
2014-04-29 03:34:26 +00:00
|
|
|
res.remove('Content-Length');
|
2013-11-13 17:01:15 +00:00
|
|
|
res.length.should.equal(3);
|
|
|
|
|
2014-04-29 03:34:26 +00:00
|
|
|
res.body = 'foo';
|
2013-11-13 17:01:15 +00:00
|
|
|
res.length.should.equal(3);
|
2014-04-29 03:34:26 +00:00
|
|
|
|
|
|
|
res.body = new Buffer('foo bar');
|
|
|
|
res.remove('Content-Length');
|
|
|
|
res.length.should.equal(7);
|
|
|
|
|
|
|
|
res.body = new Buffer('foo bar');
|
|
|
|
res.length.should.equal(7);
|
|
|
|
|
|
|
|
res.body = { hello: 'world' };
|
|
|
|
res.remove('Content-Length');
|
|
|
|
res.length.should.equal(17);
|
|
|
|
|
|
|
|
res.body = { hello: 'world' };
|
|
|
|
res.length.should.equal(17);
|
|
|
|
|
|
|
|
res.body = fs.createReadStream('package.json');
|
|
|
|
should.not.exist(res.length);
|
|
|
|
|
|
|
|
res.body = null;
|
|
|
|
should.not.exist(res.length);
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and .body is not', function(){
|
|
|
|
it('should return undefined', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const res = response();
|
2013-11-13 17:01:15 +00:00
|
|
|
assert(null == res.length);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-29 03:34:26 +00:00
|
|
|
})
|