diff --git a/lib/context.js b/lib/context.js index 0cbf207..e7b10b8 100644 --- a/lib/context.js +++ b/lib/context.js @@ -25,6 +25,7 @@ const proto = module.exports = { */ inspect() { + if (this === proto) return this; return this.toJSON(); }, diff --git a/test/context/inspect.js b/test/context/inspect.js index 9aa0285..98edf96 100644 --- a/test/context/inspect.js +++ b/test/context/inspect.js @@ -1,6 +1,7 @@ 'use strict'; +const prototype = require('../../lib/context'); const assert = require('assert'); const context = require('../helpers/context'); @@ -11,4 +12,9 @@ describe('ctx.inspect()', () => { assert.deepEqual(toJSON, ctx.inspect()); }); + + // console.log(require.cache) will call prototype.inspect() + it('should not crash when called on the prototype', () => { + assert.deepEqual(prototype, prototype.inspect()); + }); });