1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 09:10:40 -05:00

testing/asserts: Add unimplemented and unreachable (#248)

This commit is contained in:
Ryan Dahl 2019-03-08 02:32:46 -05:00 committed by GitHub
parent afaf343f37
commit 02274ef48b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View file

@ -283,3 +283,13 @@ export async function assertThrowsAsync(
throw new Error(msg);
}
}
/** Use this to stub out methods that will throw when invoked. */
export function unimplemented(msg?: string): never {
throw new Error(msg || "unimplemented");
}
/** Use this to assert unreachable code. */
export function unreachable(): never {
throw new Error("unreachable");
}

View file

@ -7,7 +7,9 @@ import {
assertStrContains,
assertArrayContains,
assertMatch,
assertEquals
assertEquals,
unimplemented,
unreachable
} from "./asserts.ts";
import { test } from "./mod.ts";
// import { assertEquals as prettyAssertEqual } from "./pretty.ts";
@ -112,3 +114,25 @@ test(function testingAssertStringMatchingThrows() {
}
assert(didThrow);
});
test(function testingAssertsUnimplemented() {
let didThrow = false;
try {
unimplemented();
} catch (e) {
assert(e.message === "unimplemented");
didThrow = true;
}
assert(didThrow);
});
test(function testingAssertsUnreachable() {
let didThrow = false;
try {
unreachable();
} catch (e) {
assert(e.message === "unreachable");
didThrow = true;
}
assert(didThrow);
});