koa-lite/test/request/inspect.js
Ruben Bridgewater 8f047ddb84 fix: use non deprecated custom inspect (#1198)
Custom inspection with the `inspect` property is deprecated and will
not work in Node.js 11 anymore. This fixes it by using the custom
inspect symbol where existent and falls back to the old style in case
it does not exist.
2018-06-25 10:34:15 +08:00

36 lines
863 B
JavaScript

'use strict';
const request = require('../helpers/context').request;
const assert = require('assert');
const util = require('util');
describe('req.inspect()', () => {
describe('with no request.req present', () => {
it('should return null', () => {
const req = request();
req.method = 'GET';
delete req.req;
assert(undefined === req.inspect());
assert('undefined' === util.inspect(req));
});
});
it('should return a json representation', () => {
const req = request();
req.method = 'GET';
req.url = 'example.com';
req.header.host = 'example.com';
const expected = {
method: 'GET',
url: 'example.com',
header: {
host: 'example.com'
}
};
assert.deepEqual(req.inspect(), expected);
assert.deepEqual(util.inspect(req), util.inspect(expected));
});
});