summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--globals.ts7
-rw-r--r--tests.ts12
2 files changed, 19 insertions, 0 deletions
diff --git a/globals.ts b/globals.ts
index ed60bc46a..b8944b4be 100644
--- a/globals.ts
+++ b/globals.ts
@@ -32,6 +32,13 @@ _global["console"] = {
// tslint:disable-next-line:no-any
error(...args: any[]): void {
print("ERROR: " + stringifyArgs(args));
+ },
+
+ // tslint:disable-next-line:no-any
+ assert(condition: boolean, ...args: any[]): void {
+ if (!condition) {
+ throw new Error("Assertion failed: " + stringifyArgs(args));
+ }
}
};
diff --git a/tests.ts b/tests.ts
index d4b188fda..406ac76e8 100644
--- a/tests.ts
+++ b/tests.ts
@@ -19,6 +19,18 @@ test(async function tests_fetch() {
assertEqual(json.name, "deno");
});
+test(function tests_console_assert() {
+ console.assert(true);
+
+ let hasThrown = false;
+ try {
+ console.assert(false);
+ } catch {
+ hasThrown = true;
+ }
+ assertEqual(hasThrown, true);
+});
+
test(async function tests_readFileSync() {
const data = readFileSync("package.json");
if (!data.byteLength) {