summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/asserts.ts10
-rw-r--r--testing/asserts_test.ts26
2 files changed, 35 insertions, 1 deletions
diff --git a/testing/asserts.ts b/testing/asserts.ts
index 233219b6a..6431a11a5 100644
--- a/testing/asserts.ts
+++ b/testing/asserts.ts
@@ -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");
+}
diff --git a/testing/asserts_test.ts b/testing/asserts_test.ts
index 6227543e5..ccec2af09 100644
--- a/testing/asserts_test.ts
+++ b/testing/asserts_test.ts
@@ -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);
+});