From cff68af96552fcbfd9317144c1a2d84004d4f91b Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 20 Apr 2020 16:23:07 +0100 Subject: [PATCH] LibJS: Add JSDoc to test-common.js --- Libraries/LibJS/Tests/test-common.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Libraries/LibJS/Tests/test-common.js b/Libraries/LibJS/Tests/test-common.js index 1e7ab23b79..cdc1336539 100644 --- a/Libraries/LibJS/Tests/test-common.js +++ b/Libraries/LibJS/Tests/test-common.js @@ -1,4 +1,9 @@ - +/** + * Custom error for failed assertions. + * @constructor + * @param {string} message Error message + * @returns Error + */ function AssertionError(message) { var instance = new Error(message); instance.name = 'AssertionError'; @@ -6,16 +11,32 @@ function AssertionError(message) { return instance; } +/** + * Throws an `AssertionError` if `value` is not truthy. + * @param {*} value Value to be tested + */ function assert(value) { if (!value) throw new AssertionError("The assertion failed!"); } +/** + * Throws an `AssertionError` when called. + * @throws {AssertionError} + */ function assertNotReached() { 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 { testFunction(); assertNotReached();