diff options
author | Yingbo (Max) Wang <maxwyb@gmail.com> | 2018-09-30 15:10:20 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-30 18:10:20 -0400 |
commit | bcdbfc00f01a94fed1d3f1d11f8aacc627c5ca36 (patch) | |
tree | 0c57bd747dd6fc742f81a0f3d77fc16e94f59601 /js/console_test.ts | |
parent | 50a9c2b575b383e72f64e16e83e540c215482e73 (diff) |
Limit depth of output in console.log for nested objects, and add console.dir (#826)
Diffstat (limited to 'js/console_test.ts')
-rw-r--r-- | js/console_test.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/js/console_test.ts b/js/console_test.ts index 94a627a5f..9e6a37256 100644 --- a/js/console_test.ts +++ b/js/console_test.ts @@ -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) { |