From 6b95b25000a713cb86cdb5ddceb5aa46c819962e Mon Sep 17 00:00:00 2001 From: xcatliu Date: Thu, 27 Aug 2020 17:03:15 +0800 Subject: feat(std/testing): add assertNotMatch (#6775) --- std/testing/asserts.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'std/testing/asserts.ts') 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 @@ -409,6 +409,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 */ -- cgit v1.2.3