Skip to content

Commit

Permalink
testing: add fail() (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j authored and ry committed Jan 26, 2019
1 parent ec1675a commit c1c18c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions testing/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions testing/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c1c18c9

Please sign in to comment.