From 83770e898e365579dcc30650f706116a312bd9f6 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Tue, 27 Apr 2021 11:54:47 +0200 Subject: fix(console): circular customInspect (#10338) --- cli/tests/unit/console_test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'cli/tests') diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index d7c4fd0cb..a43bfdba3 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -342,6 +342,14 @@ unitTest(function consoleTestStringifyCircular(): void { stringify({ str: 1, [Symbol.for("sym")]: 2, [Symbol.toStringTag]: "TAG" }), 'TAG { str: 1, [Symbol(sym)]: 2, [Symbol(Symbol.toStringTag)]: "TAG" }', ); + assertEquals( + stringify({ + [Deno.customInspect]: function () { + return Deno.inspect(this); + }, + }), + "[Circular]", + ); // test inspect is working the same assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected); }); @@ -878,12 +886,19 @@ unitTest(function consoleTestWithCustomInspectorError(): void { } } + const a = new A(); assertThrows( - () => stringify(new A()), + () => stringify(a), Error, "BOOM", "Custom inspect won't attempt to parse if user defined function throws", ); + assertThrows( + () => stringify(a), + Error, + "BOOM", + "Inpsect should fail and maintain a clear CTX_STACK", + ); }); unitTest(function consoleTestWithCustomInspectFunction(): void { -- cgit v1.2.3