summaryrefslogtreecommitdiff
path: root/std/testing/asserts.ts
diff options
context:
space:
mode:
authorxcatliu <xcatliu@gmail.com>2020-08-27 17:03:15 +0800
committerGitHub <noreply@github.com>2020-08-27 11:03:15 +0200
commit6b95b25000a713cb86cdb5ddceb5aa46c819962e (patch)
treea17ceb6bf752a801b86577d290ca375b36d96d0c /std/testing/asserts.ts
parente1564f385c770ac37c550f7d9e164d6a846c191e (diff)
feat(std/testing): add assertNotMatch (#6775)
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r--std/testing/asserts.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts
index fe8b90f63..aa3017a4c 100644
--- a/std/testing/asserts.ts
+++ b/std/testing/asserts.ts
@@ -410,6 +410,23 @@ export function assertMatch(
}
/**
+ * Make an assertion that `actual` not match RegExp `expected`. If match
+ * then thrown
+ */
+export function assertNotMatch(
+ actual: string,
+ expected: RegExp,
+ msg?: string,
+): void {
+ if (expected.test(actual)) {
+ if (!msg) {
+ msg = `actual: "${actual}" expected to not match: "${expected}"`;
+ }
+ throw new AssertionError(msg);
+ }
+}
+
+/**
* Forcefully throws a failed assertion
*/
export function fail(msg?: string): void {