mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibJS: Add JSDoc to test-common.js
This commit is contained in:
parent
e578b7884b
commit
cff68af965
1 changed files with 23 additions and 2 deletions
|
@ -1,4 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Custom error for failed assertions.
|
||||||
|
* @constructor
|
||||||
|
* @param {string} message Error message
|
||||||
|
* @returns Error
|
||||||
|
*/
|
||||||
function AssertionError(message) {
|
function AssertionError(message) {
|
||||||
var instance = new Error(message);
|
var instance = new Error(message);
|
||||||
instance.name = 'AssertionError';
|
instance.name = 'AssertionError';
|
||||||
|
@ -6,16 +11,32 @@ function AssertionError(message) {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws an `AssertionError` if `value` is not truthy.
|
||||||
|
* @param {*} value Value to be tested
|
||||||
|
*/
|
||||||
function assert(value) {
|
function assert(value) {
|
||||||
if (!value)
|
if (!value)
|
||||||
throw new AssertionError("The assertion failed!");
|
throw new AssertionError("The assertion failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws an `AssertionError` when called.
|
||||||
|
* @throws {AssertionError}
|
||||||
|
*/
|
||||||
function assertNotReached() {
|
function assertNotReached() {
|
||||||
throw new AssertionError("assertNotReached() was reached!");
|
throw new AssertionError("assertNotReached() was reached!");
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertThrowsError(testFunction, options) {
|
/**
|
||||||
|
* Ensures the provided functions throws a specific error.
|
||||||
|
* @param {Function} testFunction Function executing the throwing code
|
||||||
|
* @param {object} [options]
|
||||||
|
* @param {Error} [options.error] Expected error type
|
||||||
|
* @param {string} [options.name] Expected error name
|
||||||
|
* @param {string} [options.message] Expected error message
|
||||||
|
*/
|
||||||
|
function assertThrowsError(testFunction, options = {}) {
|
||||||
try {
|
try {
|
||||||
testFunction();
|
testFunction();
|
||||||
assertNotReached();
|
assertNotReached();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue