From be65b2b0f69c32d0ac357976665c702adca02e37 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sat, 26 Jan 2019 11:51:19 +0000 Subject: [PATCH] testing: add fail() (denoland/deno_std#123) Original: https://github.com/denoland/deno_std/commit/c1c18c9469663ec54177d2b25f9778227b7dc813 --- testing/mod.ts | 7 +++++++ testing/test.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/testing/mod.ts b/testing/mod.ts index 762d37c48a..06089a80ad 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -74,6 +74,13 @@ const assertions = { } }, + /** + * Forcefully throws a failed assertion + */ + fail(msg?: string): void { + assert(false, `Failed assertion${msg ? `: ${msg}` : "."}`); + }, + /** Executes a function, expecting it to throw. If it does not, then it * throws. An error class and a string that should be included in the * error message can also be asserted. diff --git a/testing/test.ts b/testing/test.ts index 1765fd6b6b..347a31b568 100644 --- a/testing/test.ts +++ b/testing/test.ts @@ -31,6 +31,13 @@ test(function testingAssertEqual() { assert(assertEqual === assert.equal); }); +test(function testingAssertFail() { + let didThrow = false; + + assert.throws(assert.fail, Error, "Failed assertion."); + assert.throws(() => { assert.fail("foo"); }, Error, "Failed assertion: foo"); +}); + test(function testingAssertEqualActualUncoercable() { let didThrow = false; const a = Object.create(null);