diff options
author | Nathan Rajlich <nathan@tootallnate.net> | 2013-01-29 18:44:29 -0800 |
---|---|---|
committer | Nathan Rajlich <nathan@tootallnate.net> | 2013-03-12 13:15:03 -0700 |
commit | da8b0eefde10d24b22dc87c32d5fc76be41874f0 (patch) | |
tree | f3cc621e4c25d94d52b3b2d76030f3f402cfa34b /test | |
parent | 43c1830e0a9c046d0209421ca732187e1cc3d938 (diff) | |
download | node-new-da8b0eefde10d24b22dc87c32d5fc76be41874f0.tar.gz |
console: `console.dir()` bypasses inspect() methods
Use the `customInspect: false` option of `util.inspect()` to bypass any custom
inspect() function on the object being logged.
Closes #2717.
Diffstat (limited to 'test')
-rw-r--r-- | test/simple/test-console.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/test/simple/test-console.js b/test/simple/test-console.js index bef8772a8f..722945eaf2 100644 --- a/test/simple/test-console.js +++ b/test/simple/test-console.js @@ -31,27 +31,38 @@ assert.ok(process.stderr.writable); assert.equal('number', typeof process.stdout.fd); assert.equal('number', typeof process.stderr.fd); +// an Object with a custom .inspect() function +var custom_inspect = { foo: 'bar', inspect: function () { return 'inspect'; } }; var stdout_write = global.process.stdout.write; var strings = []; global.process.stdout.write = function(string) { strings.push(string); }; +console._stderr = process.stdout; +// test console.log() console.log('foo'); console.log('foo', 'bar'); console.log('%s %s', 'foo', 'bar', 'hop'); console.log({slashes: '\\\\'}); +console.log(custom_inspect); -console._stderr = process.stdout; +// test console.dir() +console.dir(custom_inspect); + +// test console.trace() console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo'); + global.process.stdout.write = stdout_write; assert.equal('foo\n', strings.shift()); assert.equal('foo bar\n', strings.shift()); assert.equal('foo bar hop\n', strings.shift()); assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift()); +assert.equal('inspect\n', strings.shift()); +assert.equal("{ foo: 'bar', inspect: [Function] }\n", strings.shift()); assert.equal('Trace: This is a {"formatted":"trace"} 10 foo', strings.shift().split('\n').shift()); |