diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2019-08-20 01:35:43 +1000 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-19 11:35:43 -0400 |
commit | f0a235563e1eb748f4030d19af3f9a5ac59d2550 (patch) | |
tree | b6753890b2baf6224c9facceb86d5ccf9f52ad44 /js/console_test.ts | |
parent | 4faab6a74b0f583bba5ebcc877c6ea1407d360e3 (diff) |
Support custom inspection of objects (#2791)
Diffstat (limited to 'js/console_test.ts')
-rw-r--r-- | js/console_test.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/js/console_test.ts b/js/console_test.ts index 8070ee0f0..a2f9280a1 100644 --- a/js/console_test.ts +++ b/js/console_test.ts @@ -3,8 +3,15 @@ import { assert, assertEquals, test } from "./test_util.ts"; // Some of these APIs aren't exposed in the types and so we have to cast to any // in order to "trick" TypeScript. -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const { Console, stringifyArgs, inspect, write, stdout } = Deno as any; +const { + Console, + customInspect, + stringifyArgs, + inspect, + write, + stdout + // eslint-disable-next-line @typescript-eslint/no-explicit-any +} = Deno as any; function stringify(...args: unknown[]): string { return stringifyArgs(args).replace(/\n$/, ""); @@ -173,6 +180,16 @@ test(function consoleTestStringifyWithDepth(): void { ); }); +test(function consoleTestWithCustomInspector(): void { + class A { + [customInspect](): string { + return "b"; + } + } + + assertEquals(stringify(new A()), "b"); +}); + test(function consoleTestWithIntegerFormatSpecifier(): void { assertEquals(stringify("%i"), "%i"); assertEquals(stringify("%i", 42.0), "42"); |