koa-lite/test/response/inspect.js

37 lines
872 B
JavaScript
Raw Permalink Normal View History

2014-07-06 08:43:14 +00:00
'use strict';
const response = require('../helpers/context').response;
const assert = require('assert');
const util = require('util');
2014-07-06 08:43:14 +00:00
describe('res.inspect()', () => {
describe('with no response.res present', () => {
it('should return null', () => {
const res = response();
2014-07-06 08:43:14 +00:00
res.body = 'hello';
delete res.res;
2017-05-11 03:30:32 +00:00
assert.equal(res.inspect(), null);
assert.equal(util.inspect(res), 'undefined');
2015-10-12 20:36:41 +00:00
});
});
2014-07-06 08:43:14 +00:00
it('should return a json representation', () => {
const res = response();
2014-07-06 08:43:14 +00:00
res.body = 'hello';
const expected = {
2014-07-06 08:43:14 +00:00
status: 200,
message: 'OK',
2014-07-06 08:43:14 +00:00
header: {
'content-type': 'text/plain; charset=utf-8',
'content-length': '5'
},
body: 'hello'
};
assert.deepEqual(res.inspect(), expected);
assert.deepEqual(util.inspect(res), util.inspect(expected));
2015-10-12 20:36:41 +00:00
});
});