1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

Add console.assert (#102)

This commit is contained in:
Pig Fang 2018-06-05 15:58:50 +08:00 committed by Ryan Dahl
parent 71d789198b
commit 874db2a334
2 changed files with 19 additions and 0 deletions

View file

@ -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));
}
}
};

View file

@ -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) {