mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
Limit depth of output in console.log for nested objects, and add console.dir (#826)
This commit is contained in:
parent
50a9c2b575
commit
bcdbfc00f0
2 changed files with 87 additions and 18 deletions
|
@ -68,7 +68,7 @@ test(function consoleTestStringifyCircular() {
|
|||
|
||||
nestedObj.o = circularObj;
|
||||
|
||||
const nestedObjExpected = `{ num: 1, bool: true, str: "a", method: [Function: method], asyncMethod: [AsyncFunction: asyncMethod], generatorMethod: [GeneratorFunction: generatorMethod], un: undefined, nu: null, arrowFunc: [Function: arrowFunc], extendedClass: Extended { a: 1, b: 2 }, nFunc: [Function], extendedCstr: [Function: Extended], o: { num: 2, bool: false, str: "b", method: [Function: method], un: undefined, nu: null, nested: [Circular], emptyObj: {}, arr: [ 1, "s", false, null, [Circular] ], baseClass: Base { a: 1 } } }`;
|
||||
const nestedObjExpected = `{ num: 1, bool: true, str: "a", method: [Function: method], asyncMethod: [AsyncFunction: asyncMethod], generatorMethod: [GeneratorFunction: generatorMethod], un: undefined, nu: null, arrowFunc: [Function: arrowFunc], extendedClass: Extended { a: 1, b: 2 }, nFunc: [Function], extendedCstr: [Function: Extended], o: { num: 2, bool: false, str: "b", method: [Function: method], un: undefined, nu: null, nested: [Circular], emptyObj: [object], arr: [object], baseClass: [object] } }`;
|
||||
|
||||
assertEqual(stringify(1), "1");
|
||||
assertEqual(stringify("s"), "s");
|
||||
|
@ -92,6 +92,23 @@ test(function consoleTestStringifyCircular() {
|
|||
);
|
||||
});
|
||||
|
||||
test(function consoleTestStringifyWithDepth() {
|
||||
const nestedObj: any = { a: { b: { c: { d: { e: { f: 42 } } } } } };
|
||||
assertEqual(
|
||||
stringifyArgs([nestedObj], { depth: 3 }),
|
||||
"{ a: { b: { c: [object] } } }"
|
||||
);
|
||||
assertEqual(
|
||||
stringifyArgs([nestedObj], { depth: 4 }),
|
||||
"{ a: { b: { c: { d: [object] } } } }"
|
||||
);
|
||||
assertEqual(stringifyArgs([nestedObj], { depth: 0 }), "[object]");
|
||||
assertEqual(
|
||||
stringifyArgs([nestedObj], { depth: null }),
|
||||
"{ a: { b: [object] } }"
|
||||
);
|
||||
});
|
||||
|
||||
test(function consoleTestError() {
|
||||
class MyError extends Error {
|
||||
constructor(msg: string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue