1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00

testing: add fail() (#123)

This commit is contained in:
James Garbutt 2019-01-26 11:51:19 +00:00 committed by Ryan Dahl
parent ec1675a8ca
commit c1c18c9469
2 changed files with 14 additions and 0 deletions

View file

@ -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.

View file

@ -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);