summaryrefslogtreecommitdiff
path: root/tests/unit/console_test.ts
diff options
context:
space:
mode:
authorMujahedSafaa <168719085+MujahedSafaa@users.noreply.github.com>2024-09-12 15:02:32 +0300
committerGitHub <noreply@github.com>2024-09-12 05:02:32 -0700
commit4983f763d480f73a7e0d55549afb7af87fa7f04b (patch)
tree3d866d95e3d01336d37959e7560d793ae87a07ee /tests/unit/console_test.ts
parentc9065103b8ef0317fd8141f554fdc0a2f801e844 (diff)
fix(ext/console): prevent duplicate error printing when the cause is assigned (#25327)
This commit fixes the error format when the cause is assigned separately, ensuring that the cause is only printed once instead of twice. The fix addresses issue [#21651](https://github.com/denoland/deno/issues/21651).
Diffstat (limited to 'tests/unit/console_test.ts')
-rw-r--r--tests/unit/console_test.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/unit/console_test.ts b/tests/unit/console_test.ts
index 63ffff0dc..201d18f00 100644
--- a/tests/unit/console_test.ts
+++ b/tests/unit/console_test.ts
@@ -1894,6 +1894,25 @@ Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedTypedArray() {
});
});
+Deno.test(function consoleLogWhenCauseIsAssignedShouldNotPrintCauseTwice() {
+ mockConsole((console, out) => {
+ const typeError = new TypeError("Type incorrect");
+ const syntaxError = new SyntaxError("Improper syntax");
+ typeError.cause = syntaxError;
+ console.log(typeError);
+ const result = stripAnsiCode(out.toString());
+ // Filter out stack trace lines, keeping only the first line and the cause line
+ const filteredOutput = result
+ .split("\n")
+ .filter((line) => !line.trim().startsWith("at"))
+ .join("\n");
+
+ const expectedResult =
+ "TypeError: Type incorrect\nCaused by SyntaxError: Improper syntax\n";
+ assertEquals(filteredOutput.trim(), expectedResult.trim());
+ });
+});
+
// console.log(new Proxy(new RegExp(), {}))
Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedRegExp() {
mockConsole((console, out) => {