diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2018-12-10 12:01:02 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-10 12:01:02 -0500 |
commit | 1548792fb3530efb63432c0c704a3f0053410eb3 (patch) | |
tree | 908576c0c6c6192144edc070aef63bd9c74354ce /js/console_test.ts | |
parent | c427c2df427f477eb1214d8ff3fdfad36e191a6c (diff) |
Add more console types formatting support (#1299)
Diffstat (limited to 'js/console_test.ts')
-rw-r--r-- | js/console_test.ts | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/js/console_test.ts b/js/console_test.ts index a46edf29e..eb53ebb76 100644 --- a/js/console_test.ts +++ b/js/console_test.ts @@ -67,12 +67,30 @@ test(function consoleTestStringifyCircular() { nestedObj.o = circularObj; // tslint:disable-next-line:max-line-length - 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] } }`; + 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 } } }`; assertEqual(stringify(1), "1"); assertEqual(stringify(1n), "1n"); assertEqual(stringify("s"), "s"); assertEqual(stringify(false), "false"); + // tslint:disable-next-line:no-construct + assertEqual(stringify(new Number(1)), "[Number: 1]"); + // tslint:disable-next-line:no-construct + assertEqual(stringify(new Boolean(true)), "[Boolean: true]"); + // tslint:disable-next-line:no-construct + assertEqual(stringify(new String("deno")), `[String: "deno"]`); + assertEqual(stringify(/[0-9]*/), "/[0-9]*/"); + assertEqual( + stringify(new Date("2018-12-10T02:26:59.002Z")), + "2018-12-10T02:26:59.002Z" + ); + assertEqual(stringify(new Set([1, 2, 3])), "Set { 1, 2, 3 }"); + assertEqual( + stringify(new Map([[1, "one"], [2, "two"]])), + `Map { 1 => "one", 2 => "two" }` + ); + assertEqual(stringify(new WeakSet()), "WeakSet { [items unknown] }"); + assertEqual(stringify(new WeakMap()), "WeakMap { [items unknown] }"); assertEqual(stringify(Symbol(1)), "Symbol(1)"); assertEqual(stringify(null), "null"); assertEqual(stringify(undefined), "undefined"); @@ -84,6 +102,11 @@ test(function consoleTestStringifyCircular() { stringify(async function* agf() {}), "[AsyncGeneratorFunction: agf]" ); + assertEqual(stringify(new Uint8Array([1, 2, 3])), "Uint8Array [ 1, 2, 3 ]"); + assertEqual( + stringify({ a: { b: { c: { d: new Set([1]) } } } }), + "{ a: { b: { c: { d: [Set] } } } }" + ); assertEqual(stringify(nestedObj), nestedObjExpected); assertEqual(stringify(JSON), "{}"); assertEqual( @@ -98,16 +121,16 @@ test(function consoleTestStringifyWithDepth() { const nestedObj: any = { a: { b: { c: { d: { e: { f: 42 } } } } } }; assertEqual( stringifyArgs([nestedObj], { depth: 3 }), - "{ a: { b: { c: [object] } } }" + "{ a: { b: { c: [Object] } } }" ); assertEqual( stringifyArgs([nestedObj], { depth: 4 }), - "{ a: { b: { c: { d: [object] } } } }" + "{ a: { b: { c: { d: [Object] } } } }" ); - assertEqual(stringifyArgs([nestedObj], { depth: 0 }), "[object]"); + assertEqual(stringifyArgs([nestedObj], { depth: 0 }), "[Object]"); assertEqual( stringifyArgs([nestedObj], { depth: null }), - "{ a: { b: [object] } }" + "{ a: { b: { c: { d: [Object] } } } }" ); }); |