diff options
author | 迷渡 <justjavac@gmail.com> | 2018-12-18 00:54:33 +0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-17 11:54:33 -0500 |
commit | 04076465cf2bda0af35fa255a56516aa6f9732ad (patch) | |
tree | e08472022a14b65d0581037008f01b6a95947f06 /js/console_test.ts | |
parent | c69d2f554d05ba9e4d09af6ae451ce5676876e61 (diff) |
Add console.count and console.time (#1358)
Diffstat (limited to 'js/console_test.ts')
-rw-r--r-- | js/console_test.ts | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/js/console_test.ts b/js/console_test.ts index 3e6bd6905..2946d3648 100644 --- a/js/console_test.ts +++ b/js/console_test.ts @@ -2,6 +2,10 @@ import { test, assert, assertEqual } from "./test_util.ts"; import { stringifyArgs } from "./console.ts"; +import { Console } from "./console.ts"; +import { libdeno } from "./libdeno"; +const console = new Console(libdeno.print); + // tslint:disable-next-line:no-any function stringify(...args: any[]): string { return stringifyArgs(args); @@ -114,7 +118,7 @@ test(function consoleTestStringifyCircular() { assertEqual( stringify(console), // tslint:disable-next-line:max-line-length - "Console { printFunc: [Function], log: [Function], debug: [Function], info: [Function], dir: [Function], warn: [Function], error: [Function], assert: [Function] }" + "Console { printFunc: [Function], log: [Function], debug: [Function], info: [Function], dir: [Function], warn: [Function], error: [Function], assert: [Function], count: [Function], countReset: [Function], time: [Function], timeLog: [Function], timeEnd: [Function] }" ); }); @@ -136,6 +140,22 @@ test(function consoleTestStringifyWithDepth() { ); }); +test(function consoleTestCallToStringOnLabel() { + const methods = ["count", "countReset", "time", "timeLog", "timeEnd"]; + + for (const method of methods) { + let hasCalled = false; + + console[method]({ + toString() { + hasCalled = true; + } + }); + + assertEqual(hasCalled, true); + } +}); + test(function consoleTestError() { class MyError extends Error { constructor(errStr: string) { @@ -159,6 +179,11 @@ test(function consoleDetachedLog() { const warn = console.warn; const error = console.error; const consoleAssert = console.assert; + const consoleCount = console.count; + const consoleCountReset = console.countReset; + const consoleTime = console.time; + const consoleTimeLog = console.timeLog; + const consoleTimeEnd = console.timeEnd; log("Hello world"); dir("Hello world"); debug("Hello world"); @@ -166,4 +191,9 @@ test(function consoleDetachedLog() { warn("Hello world"); error("Hello world"); consoleAssert(true); + consoleCount("Hello world"); + consoleCountReset("Hello world"); + consoleTime("Hello world"); + consoleTimeLog("Hello world"); + consoleTimeEnd("Hello world"); }); |