koa-lite/test/request/inspect.js

37 lines
863 B
JavaScript
Raw Normal View History

2014-07-06 08:43:14 +00:00
'use strict';
const request = require('../helpers/context').request;
const assert = require('assert');
const util = require('util');
2014-07-06 08:43:14 +00:00
describe('req.inspect()', () => {
describe('with no request.req present', () => {
it('should return null', () => {
const req = request();
2014-07-06 08:43:14 +00:00
req.method = 'GET';
delete req.req;
assert(undefined === req.inspect());
assert('undefined' === util.inspect(req));
2015-10-12 20:36:41 +00:00
});
});
2014-07-06 08:43:14 +00:00
it('should return a json representation', () => {
const req = request();
2014-07-06 08:43:14 +00:00
req.method = 'GET';
req.url = 'example.com';
req.header.host = 'example.com';
const expected = {
2014-07-06 08:43:14 +00:00
method: 'GET',
url: 'example.com',
header: {
host: 'example.com'
}
};
assert.deepEqual(req.inspect(), expected);
assert.deepEqual(util.inspect(req), util.inspect(expected));
2015-10-12 20:36:41 +00:00
});
});