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:
parent
ec1675a8ca
commit
c1c18c9469
2 changed files with 14 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue