diff --git a/dist/unit-test-framework.ts b/dist/unit-test-framework.ts index ee5e1f4..095eced 100644 --- a/dist/unit-test-framework.ts +++ b/dist/unit-test-framework.ts @@ -18,13 +18,13 @@ // #region AssertionError /** - * AssertionError is a custom error type used to indicate assertion failures in tests or validation utilities. + * `AssertionError` is a custom error type used to indicate assertion failures in tests or validation utilities. * This error is intended to be thrown by assertion methods (such as those in a custom Assert class) when a condition - * that should always be true is found to be false. Using a specific AssertionError type allows for more precise + * that should always be true is found to be false. Using a specific `AssertionError` type allows for more precise * error handling and clearer reporting in test environments, as assertion failures can be easily distinguished from * other kinds of runtime errors. * @example - * ```typescript + * ```ts * if (actual !== expected) { * throw new AssertionError(`Expected ${expected}, but got ${actual}`) * } @@ -58,10 +58,11 @@ class Assert { * Asserts that the provided function throws an error. * Optionally checks the error type and message. * @param fn - A function that is expected to throw an error. - * Must be passed as a function reference, e.g. '() => codeThatThrows()'. - * @param expectedErrorType - (Optional) Expected constructor of the thrown error (e.g., 'TypeError'). + * Must be passed as a function reference, e.g. `() => codeThatThrows()`. + * @param expectedErrorType - (Optional) Expected constructor of the thrown error (e.g., `TypeError`). * @param expectedMessage - (Optional) Exact expected error message. * @param message - (Optional) Additional prefix for the error message if the assertion fails. + * @returns {asserts fn is () => never} - Asserts that 'fn' will throw an error if the assertion passes. * @throws AssertionError - If no error is thrown, or if the thrown error does not match the expected type or message. * @example * ```ts @@ -69,7 +70,7 @@ class Assert { * throw new TypeError("Invalid") * }, TypeError, "Invalid", "Should throw TypeError") * ``` - * @see Assert.doesNotThrow for the opposite assertion. + * @see {@link Assert.doesNotThrow} for the opposite assertion. */ public static throws( fn: () => void, @@ -104,14 +105,15 @@ class Assert { /** * Asserts that two values are equal by type and value. * Supports comparison of primitive types, one-dimensional arrays of primitives, - * and one-dimensional arrays of objects (deep equality via JSON.stringify). + * and one-dimensional arrays of objects (deep equality via `JSON.stringify`). * If the values differ, a detailed error is thrown. * For arrays, mismatches include index, value, and type. - * For arrays of objects, a shallow comparison using JSON.stringify is performed. + * For arrays of objects, a shallow comparison using `JSON.stringify` is performed. * If a value cannot be stringified (e.g., due to circular references), it is treated as "[unprintable value]" in error messages and object equality checks. * @param actual - The actual value. * @param expected - The expected value. * @param message - (Optional) Prefix message included in the thrown error on failure. + * @returns {asserts actual is T} - Asserts that 'actual' is of type `T` if the assertion passes. * @throws AssertionError - If 'actual' and 'expected' are not equal. * @example * ```ts @@ -121,6 +123,7 @@ class Assert { * Assert.equals([{x:1}], [{x:1}], "Object array match") // Passes * Assert.equals([{x:1}], [{x:2}], "Object array mismatch") // Fails * ``` + * @see {@link Assert.notEquals} for the opposite assertion. */ public static equals(actual: T, expected: T, message: string = ""): asserts actual is T { const PREFIX = message ? `${message}: ` : ""; @@ -177,8 +180,9 @@ class Assert { * guarding against unsafe or error-throwing `toString()` implementations. * @param value - The value to test. * @param message - Optional message to prefix in case of failure. + * @returns {asserts value is null} - Narrows the type of 'value' to `null` if the assertion passes. * @throws AssertionError if the value is not exactly `null`. - * * @example + * @example * ```ts * Assert.isNull(null, "Value should be null") * Assert.isNull(undefined, "Value should not be undefined") // Fails @@ -187,7 +191,7 @@ class Assert { * Assert.isNull(undefined) // Fails * Assert.isNull(0) // Fails * ``` - * @see Assert.isDefined for an alias that checks for defined values (not `null` or `undefined`). + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `null` or `undefined`). */ public static isNull(value: unknown, message: string = ""): asserts value is null { const PREFIX = message ? `${message}: ` : "" @@ -207,14 +211,15 @@ class Assert { * Narrows the type of 'value' to NonNullable if assertion passes. * @param value - The value to test. * @param message - Optional message to prefix in case of failure. + * @returns {asserts value is NonNullable} - Narrows the type of 'value' to NonNullable if the assertion passes. * @throws AssertionError if the value is `null`. * @example * ```ts * Assert.isNotNull(42, "Value should not be null") * Assert.isNotNull(null, "Value should be null") // Fails * ``` - * @see Assert.isNull for the opposite assertion. - * @see Assert.isDefined for an alias that checks for defined values (not `null` or `undefined`). + * @see {@link Assert.isNull} for the opposite assertion. + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `null` or `undefined`). */ public static isNotNull(value: T, message: string = ""): asserts value is NonNullable { const PREFIX = message ? `${message}: ` : "" @@ -233,7 +238,8 @@ class Assert { * regardless of any conditions or assertions. * @param message - (Optional) The failure message to display. * If not provided, a default "Assertion failed" message is used. - * @throws AssertionError - Always throws an AssertionError with the provided message. + * @returns {never} - This method never returns, it always throws an error. + * @throws AssertionError - Always throws an `AssertionError` with the provided message. * @example * ```ts * Assert.fail("This test should not pass") @@ -248,8 +254,9 @@ class Assert { /** * Asserts that a value is of the specified primitive type. * @param value - The value to check. - * @param type - The expected type as a string ("string", "number", etc.) + * @param type - The expected type as a string (`string`, `number`, etc.) * @param message - Optional error message. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the type does not match. * @example * ```ts @@ -259,11 +266,11 @@ class Assert { * isType([], "object", "Expected an object"); // passes * isType(null, "object", "Expected an object"); // throws * ``` - * @remarks This method checks the type using `typeof` and throws an AssertionError if the type does not match. + * @remarks This method checks the type using `typeof` and throws an `AssertionError` if the type does not match. * It is useful for validating input types in functions or methods. - * The `type` parameter must be one of the following strings: "string", "number", "boolean", "object", "function", "undefined", "symbol", or "bigint". + * The `type` parameter must be one of the following strings: `string`, `number`, `boolean`, `object`, `function`, `undefined`, `symbol`, or `bigint`. * If the value is `null`, it will be considered an object, which is consistent with JavaScript's behavior. - * @see Assert.isNotType for the opposite assertion. + * @see {@link Assert.isNotType} for the opposite assertion. */ public static isType( value: unknown, @@ -283,8 +290,9 @@ class Assert { /** * Asserts that a value is NOT of the specified primitive type. * @param value - The value to check. - * @param type - The unwanted type as a string ("string", "number", etc.) + * @param type - The unwanted type as a string (`string`, `number`, etc.) * @param message - Optional error message. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the type matches. * @example * ```ts @@ -293,9 +301,9 @@ class Assert { * isNotType({}, "object"); // throws * isNotType(null, "object", "Should not be object"); // throws (null is object in JS) * ``` - * @remarks This method checks the type using `typeof` and throws an AssertionError if the type matches. - * The `type` parameter must be one of the following strings: "string", "number", "boolean", "object", "function", "undefined", "symbol", or "bigint". - * @see Assert.isType for the positive assertion. + * @remarks This method checks the type using `typeof` and throws an `AssertionError` if the type matches. + * The `type` parameter must be one of the following strings: `string`, `number`, `boolean`, `object`, `function`, `undefined`, `symbol`, or `bigint`. + * @see {@link Assert.isType} for the positive assertion. */ public static isNotType( value: unknown, @@ -314,10 +322,11 @@ public static isNotType( // #region doesNotThrow /** * Asserts that the provided function does NOT throw an error. - * If an error is thrown, an AssertionError is thrown with the provided message or details of the error. + * If an error is thrown, an `AssertionError` is thrown with the provided message or details of the error. * @param fn - A function that is expected to NOT throw. - * Must be passed as a function reference, e.g. '() => codeThatShouldNotThrow()'. + * Must be passed as a function reference, e.g. `() => codeThatShouldNotThrow()`. * @param message - (Optional) Prefix for the error message if the assertion fails. + * @return {void} - This method does not return a value. * @throws AssertionError - If the function throws any error. * @example * ```ts @@ -325,7 +334,7 @@ public static isNotType( * const x = 1 + 1 * }, "Should not throw any error") * ``` - * @see Assert.throws for the opposite assertion. + * @see {@link Assert.throws} for the opposite assertion. */ public static doesNotThrow(fn: () => void, message: string = ""): void { const PREFIX = message ? `${message}: ` : "" @@ -343,13 +352,14 @@ public static isNotType( * Throws AssertionError if the value is not truthy. * @param value - The value to test for truthiness. * @param message - (Optional) Message to prefix in case of failure. + * @returns {asserts value} - Narrows the type of 'value' to its original type if the assertion passes. * @throws AssertionError - If the value is not truthy. * @example * ```ts * Assert.isTrue(1 < 2, "Math sanity") * Assert.isTrue("non-empty string", "String should be truthy") * ``` - * @see Assert.isFalse for the opposite assertion. + * @see {@link Assert.isFalse} for the opposite assertion. */ public static isTrue(value: unknown, message: string = ""): asserts value { const PREFIX = message ? `${message}: ` : "" @@ -365,6 +375,7 @@ public static isNotType( * Throws AssertionError if the value is not falsy. * @param value - The value to test for falsiness. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the value is not falsy. * @example * ```ts @@ -375,7 +386,7 @@ public static isNotType( * Assert.isFalse(0, "Zero should be falsy") * Assert.isFalse("", "Empty string should be falsy") * ``` - * @see Assert.isTrue for the opposite assertion. + * @see {@link Assert.isTrue} for the opposite assertion. */ public static isFalse(value: unknown, message: string = ""): void { const PREFIX = message ? `${message}: ` : "" @@ -391,6 +402,7 @@ public static isNotType( * Throws AssertionError if the value is not exactly `undefined`. * @param value - The value to check. * @param message - (Optional) Message to prefix in case of failure. + * @returns {asserts value is undefined} - Narrows the type of 'value' to `undefined` if the assertion passes. * @throws AssertionError - If the value is not `undefined`. * @example * ```ts @@ -398,8 +410,8 @@ public static isNotType( * Assert.isUndefined(undefined) * Assert.isUndefined(null, "Null is not undefined") // Fails * ``` - * @see Assert.isNotUndefined for the opposite assertion. - * @see Assert.isDefined for an alias that checks for defined values (not `undefined`). + * @see {@link Assert.isNotUndefined} for the opposite assertion. + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `undefined`). */ public static isUndefined(value: unknown, message: string = ""): asserts value is undefined { const PREFIX = message ? `${message}: ` : "" @@ -413,9 +425,10 @@ public static isNotType( /** * Asserts that the given value is not `undefined`. * Narrows the type to exclude undefined. - * Throws AssertionError if the value is `undefined`. + * Throws `AssertionError` if the value is `undefined`. * @param value - The value to check. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the value is `undefined`. * @example * ```ts @@ -424,8 +437,8 @@ public static isNotType( * Assert.isNotUndefined(42) * Assert.isNotUndefined(null) * ``` - * @see Assert.isUndefined for the opposite assertion. - * @see Assert.isDefined for an alias that checks for defined values (not `undefined`). + * @see {@link Assert.isUndefined} for the opposite assertion. + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `undefined`). */ public static isNotUndefined(value: T, message: string = ""): asserts value is Exclude { const PREFIX = message ? `${message}: ` : "" @@ -438,9 +451,10 @@ public static isNotType( // #region isDefined /** * Asserts that the given value is defined (not `undefined`). - * Alias for isNotUndefined. + * Alias for `isNotUndefined` method. * @param value - The value to check. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the value is `undefined`. * @example * ```ts @@ -449,8 +463,8 @@ public static isNotType( * Assert.isDefined(42) * Assert.isDefined(null) * ``` - * @see Assert.isNotUndefined for the opposite assertion. - * @see Assert.isUndefined for an alias that checks for undefined values. + * @see {@link Assert.isNotUndefined} for the opposite assertion. + * @see {@link Assert.isUndefined} for an alias that checks for undefined values. */ public static isDefined(value: T, message: string = ""): asserts value is Exclude { Assert.isNotUndefined(value, message) @@ -460,11 +474,12 @@ public static isNotType( // #region notEquals /** * Asserts that two values are not equal (deep comparison). - * For arrays and objects, uses deep comparison (via JSON.stringify). - * Throws AssertionError if the values are equal. + * For arrays and objects, uses deep comparison (via `JSON.stringify`). + * Throws `AssertionError` if the values are equal. * @param actual - The actual value. * @param notExpected - The value that should NOT match. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If values are equal. * @example * ````ts @@ -474,7 +489,7 @@ public static isNotType( * Assert.notEquals(1, 2) * Assert.notEquals([1,2], [2,1]) * ``` - * @see Assert.equals for the opposite assertion. + * @see {@link Assert.equals} for the opposite assertion. */ public static notEquals(actual: T, notExpected: T, message: string = ""): void { const PREFIX = message ? `${message}: ` : "" @@ -490,12 +505,13 @@ public static isNotType( // #region contains /** * Asserts that an array or string contains a specified value or substring. - * For arrays, uses indexOf for shallow equality. - * For strings, uses indexOf for substring check. - * Throws AssertionError if the value is not found. + * For arrays, uses `indexOf` for shallow equality. + * For strings, uses `indexOf` for substring check. + * Throws `AssertionError` if the value is not found. * @param container - The array or string to search. * @param value - The value (or substring) to search for. * @param message - (Optional) Message to prefix in case of failure. + * @return {void} - This method does not return a value. * @throws AssertionError - If the value is not found. * @example * ```ts @@ -528,10 +544,11 @@ public static isNotType( // #region isInstanceOf /** * Asserts that the value is an instance of the specified constructor. - * Throws AssertionError if not. + * Throws `AssertionError` if not. * @param value - The value to check. * @param ctor - The class/constructor function. * @param message - Optional error message prefix. + * @return {void} - This method does not return a value. * @throws AssertionError - If the value is not an instance of the constructor. * @example * ```ts @@ -568,10 +585,11 @@ public static isNotType( // #region isNotInstanceOf /** * Asserts that the value is NOT an instance of the specified constructor. - * Throws AssertionError if it is. + * Throws `AssertionError` if it is. * @param value - The value to check. * @param ctor - The class/constructor function. * @param message - Optional error message prefix. + * @return {void} - This method does not return a value. * @throws AssertionError - If the value is an instance of the constructor. * @example * ```ts @@ -581,7 +599,7 @@ public static isNotType( * Assert.isNotInstanceOf(instance, MyClass) // Fails * Assert.isNotInstanceOf(42, MyClass) // Passes, since 42 is not an instance of MyClass * ``` - * @see Assert.isInstanceOf for the opposite assertion. + * @see {@link Assert.isInstanceOf} for the opposite assertion. */ public static isNotInstanceOf( value: unknown, @@ -608,6 +626,7 @@ public static isNotType( * @param a - Actual array. * @param b - Expected array. * @param message - (Optional) Prefix message for errors. + * @returns {boolean} - Returns true if arrays are equal, otherwise throws an error. * @throws AssertionError - If arrays differ in length, type, or value at any index. * @private */ @@ -647,8 +666,8 @@ public static isNotType( /** * Returns a safe string representation of any value, handling cases where * toString may throw or misbehave. Used internally by assertion methods. - * Tries JSON.stringify, then value.toString(), then Object.prototype.toString.call(value). - * If all fail, returns "[unprintable value]". + * Tries `JSON.stringify`, then `value.toString()`, then `Object.prototype.toString.call(value)`. + * If all fail, returns `[unprintable value]`. * @param value - The value to stringify. * @returns A string representation of the value, or "[unprintable value]" if not possible. * @private @@ -692,13 +711,14 @@ public static isNotType( * A utility class for managing and running test cases with controlled console output. * TestRunner' supports configurable verbosity levels and allows structured logging * with indentation for better test output organization. It is primarily designed for - * test cases using assertion methods (e.g., 'Assert.equals', 'Assert.throws'). - * Verbosity can be set via the 'TestRunner.VERBOSITY': constant object (enum pattern) - * - 'OFF' (0): No output - * - 'HEADER' (1): High-level section headers only - * - 'SECTION' (2): Full nested titles + * test cases using assertion methods (e.g., `Assert.equals`, `Assert.throws`). + * Verbosity can be set via the `TestRunner.VERBOSITY`: constant object (enum pattern) + * - `OFF` (0): No output + * - `HEADER` (1): High-level section headers only + * - `SECTION` (2): Full nested titles + * - `SUBSECTION` (3): Detailed test case titles * Verbosity level is incremental, i.e. allows all logging events with indentation level that is - * lower or equal than TestRunner.VERBOSITY. + * lower or equal than `TestRunner.VERBOSITY`. * * @example * ```ts @@ -721,9 +741,9 @@ public static isNotType( * the error will be caught and reported with context. */ class TestRunner { - private static readonly START = "START" as const; - private static readonly END = "END" as const; - private static readonly HEADER_TK = "*"; + private static readonly START = "START" as const + private static readonly END = "END" as const + private static readonly HEADER_TK = "*" /**Verbosity level */ public static readonly VERBOSITY = { diff --git a/docs/typedoc/assets/search.js b/docs/typedoc/assets/search.js index aac1956..ebbe3d6 100644 --- a/docs/typedoc/assets/search.js +++ b/docs/typedoc/assets/search.js @@ -1 +1 @@ -window.searchData = "eJytmFtv2zgQhf/L7CvhesZX+W0XTYEAixToZgMsBKNQbboVVqGyEp22MPzfF9TFHJqMzSp5SiDNOYeUP5LSHKAqv9ewSg/wb662sEJaClDZo4QV/F7XstIgYF8VsIJNkdW1rN+1l0ff9GMBor8KK4Cj6F1mSCeXTalqXe03uqwuWf3m1jFbAU9ZJZW2I7JBNJ4ueZLOclVfi+mLhmRsS1nflfr+W1V+v5hjClWpdVc4JEv+t8+Ky7M5lQzx32V5cdG9Kxjindfv5S5XcnsxIK+3p6phKR+yopZXMnZdzbCEW1XrTG3kx92VmLwrLHeDs+5KHR2nSv02iXf74jIGTZZqqwan/K22UUCoUu/Va6mImdJr5nNf7a9Bp9uSgf4/n676tyXD/GN/jNf+EqrUN9c3MVXqV+1jzR57OeJUEunvH4N5qW6q6sUzrL/9hseiY/kLx+NppOHp3Mtaf9orJf1ce+tNpnFmFzUFNjo2/DFNT4kPN5/++PjX7f0/V/OeZfWlrHP989fS3DP4h9xcDeqKhmZ8lfqBDfVy1lep32JePPPP7Iv0t8tLwUWnGJquc134G9x5Yl91PWUtIFdb+QNWB3iWVZ2XClZAo8koAQG7XBZb85LbxgvYlI+PxkTAttzsm3/XXdmDNHia4rb63RhEOhaUjGi+WK9F2oubG82F3sNeaYQIIkVB49EimTpC9IToCAlESqFE8oTkCCcg0klIOPGEE0c4BZFOQ8KpJ5w6whmIdBYSzjzhzBHOQaTzkHDuCeeOcAEiXYSEC0+4cIRLEOkyJFx6wqUjTECkSUiYeMLEBcDwgEF20IcHz+hp8MGgOACQSxAaLjDIEPoQoUsRGjYwyBH6IKFLEho+MMgS+jChSxMaRjDIE/pAoUsUGk4wyBT6UKFLFRpWMMgV+mChSxYaXjDIFvpwoUsXJi9uEz5f6AJGDWBBNskHjFzA6MX9iXy+6GyHaraoINkU2KRcvsgQQ0GyyeeLXL7IEEPh3dHni1y+yBBDQbLJ54tcvsgQQ0Gyyeeru9ScS8+y0nJ7255PaQpZ11Y5wOfu0Br3B+MBxrA6HI/2iFodjuyUMvdMTta/6Mn2ldRa4dJ64TLKzHktY07MqFVi0v4ljPXtOi3WlKwpRZm4bRRrNLFGkyij/gvDWkytxTTOonnNY5Nhj4jiRtF2VKzFzDrMogzc1z82Fv5k46YTeKFjfuwBU9zQWDPH+sytzTzSpWvXWI+F9VhEevDOiDViayNuaXhdFuuVWK8k3qvtOrBFxpY+xq398xYJM+NLNm6N9n0QZsJAwrg12jc7mAmjB+NWRt/RYCZsgWIc0k7HgjmxZYZxMLOeBPNhNGMczlqah9N+bTMjRg/F/ex9B4OZsHWBcQuj+6Jiy5w9Y4qbUXj7YRxTBDVrAU/5kyxyJWGVro/H/wEuOfFG"; \ No newline at end of file +window.searchData = "eJytmN1u4zYQhd9lekt4PeN/3bVoCgQossDWDVAIxkJr07tCFSqV6OwuDL97QUsyhyZjM3KuEkhzziGlj6Q8e6jK7zUk6R7+zdUGEqS5AJU9SUjg17qWlQYBu6qABNZFVtey/tBcHnzTTwWI7iokAAfRuUyQTi7rUtW62q11WV2y+sWtY7YCnrNKKm1HZINoOJ7zJJ3lqr4W0xX1ydiUsn4o9fJbVX6/mGMKVal1W9gnS/63y4rLszmV9PHfZnlx0b0t6OOd17/Lba7k5mJAXm9OVf1S/siKWl7J2LY1/RLuVa0ztZYft1di8raw3PbOeih1dJwq9fskPuyKyxgcs1RT1Ttl+fP52nsyy6Wp6p3yt9pEYadKvVO3shfz4G55astqd+2R6aakp//1V3LT+4h9Gbe+CVXqu+tbpSr1TbvlcSe/HHEqifT3D9u8VHdV9epJ2d1+x8PXsXzDIXwaaXg6S1nrTzulpJ9rb73LNM7soqbARseGP6TxKfHx7tNvH/+6X/5zNe9FVl/KOtc/35bmnvQ/5PpqUFvUN+Or1I9sqJezvkr9HvPimX9mX6S/XV4KLlpF33Sd68Lf4M4Tu6rrKSsBudrIH5Ds4UVWdV4qSIAGo8ECBGxzWWzMp3QTL2BdPj0ZEwGbcr07/rtqyx6lwdMUN9UfhiDSoaDFYIrz1Uqknfh443ih87BXjkIEkaIgHOB44gjRE6IjJBAphRLJE5IjHIFIRyHhyBOOHOEYRDoOCceecOwIJyDSSUg48YQTRzgFkU5DwqknnDrCGYh0FhLOPOHMEc5BpPOQcO4J545wASJdhIQLT7hwATA8YJAd9OHBM3qO+GBQHADIJQgNFxhkCH2I0KUIDRsY5Ah9kNAlCQ0fGGQJfZjQpQkNIxjkCX2g0CUKDScYZAp9qNClCg0rGOQKfbDQJQsNLxhkC3240KULDTMY5At9wNAljIav7THkA0YuYGSQoSCd5ANGZ1sUvRoc2KRcvsgQQ0GyyeeLXL7IEEPh3dHni1y+yBBDQbLJ54tcvsgQQ0GyyeeLXL7IEENBssnnq710PNReZKXl5r453NIUsrbzs4fP7Yk37E7VPQwh2R8O9nxL9gd2xJl7JifrvhJl8z1rrXBhvXARZeZ80zEnZtQoadj+pVjfthlkTcmaxpm4nR5rNLJGoyij7ueJtRhbi3GcxfEbkU2GzybOomn6WIuJdZhEGbjfjmws7IHQ263ar0Hmx54OTaP8WL/J+kytTaxL21GyHjPrMYv04M0bazS3RvNIo7NGkPVi6yxumbFGD1tkbOlj3NpnrRzmw1crxvuw7gAzY1xj3DLtmjHMhAGJcUu067gwE0Yhxq2wrq3CTNgiw7il4bRNmBOjGeNwZo0R5sOIxjiktTQPp/nJz1Ypw4fiXnvXRmGjYcsC49ZF+7OODYQ9Y4qbUXgbYxxTBDUrAc/5syxyJSFJV4fD/zrFPRI="; \ No newline at end of file diff --git a/docs/typedoc/classes/Assert.html b/docs/typedoc/classes/Assert.html index d8d037c..3c53ec6 100644 --- a/docs/typedoc/classes/Assert.html +++ b/docs/typedoc/classes/Assert.html @@ -1,7 +1,7 @@ Assert | officescripts-unit-testing-framework
officescripts-unit-testing-framework
    Preparing search index...

    Class Assert

    Utility class for writing unit-test-style assertions. -Provides static methods to assert value equality and exception throwing. -If an assertion fails, an informative 'AssertionError' is thrown.

    -
    Index

    Constructors

    constructor +This class provides a set of static methods to perform common assertions +such as checking equality, type, and exceptions, etc.

    +
    Index

    Constructors

    Methods

    • Asserts that an array or string contains a specified value or substring. -For arrays, uses indexOf for shallow equality. -For strings, uses indexOf for substring check. -Throws AssertionError if the value is not found.

      +For arrays, uses indexOf for shallow equality. +For strings, uses indexOf for substring check. +Throws AssertionError if the value is not found.

      Parameters

      • container: string | unknown[]

        The array or string to search.

      • value: unknown

        The value (or substring) to search for.

      • message: string = ""

        (Optional) Message to prefix in case of failure.

        -

      Returns void

      AssertionError - If the value is not found.

      +

    Returns void

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the value is not found.

    Assert.contains([1, 2, 3], 2, "Array should contain 2")
    Assert.contains("hello world", "world", "String should contain 'world'")
    Assert.contains([1, 2, 3], 4) // Fails
    Assert.contains("hello world", "test") // Fails
    Assert.contains([1,2,3], 2)
    Assert.contains("hello world", "world")
    -
    • Asserts that the provided function does NOT throw an error. -If an error is thrown, an AssertionError is thrown with the provided message or details of the error.

      +
    • Asserts that the provided function does NOT throw an error. +If an error is thrown, an AssertionError is thrown with the provided message or details of the error.

      Parameters

      • fn: () => void

        A function that is expected to NOT throw. -Must be passed as a function reference, e.g. '() => codeThatShouldNotThrow()'.

        +Must be passed as a function reference, e.g. () => codeThatShouldNotThrow().

      • message: string = ""

        (Optional) Prefix for the error message if the assertion fails.

        -

      Returns void

      AssertionError - If the function throws any error.

      +

    Returns void

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the function throws any error.

    Assert.doesNotThrow(() => {
    const x = 1 + 1
    }, "Should not throw any error")
    -

    Assert.throws for the opposite assertion.

    -
    • Asserts that two values are equal by type and value. Supports comparison of primitive types, one-dimensional arrays of primitives, -and one-dimensional arrays of objects (deep equality via JSON.stringify). +and one-dimensional arrays of objects (deep equality via JSON.stringify). If the values differ, a detailed error is thrown. For arrays, mismatches include index, value, and type. -For arrays of objects, a shallow comparison using JSON.stringify is performed. +For arrays of objects, a shallow comparison using JSON.stringify is performed. If a value cannot be stringified (e.g., due to circular references), it is treated as "[unprintable value]" in error messages and object equality checks.

      Type Parameters

      • T

      Parameters

      • actual: T

        The actual value.

      • expected: T

        The expected value.

      • message: string = ""

        (Optional) Prefix message included in the thrown error on failure.

        -

      Returns asserts actual is T

      AssertionError - If 'actual' and 'expected' are not equal.

      +

    Returns asserts actual is T

      +
    • Asserts that 'actual' is of type T if the assertion passes.
    • +
    +

    AssertionError - If 'actual' and 'expected' are not equal.

    Assert.equals(2 + 2, 4, "Simple math")
    Assert.equals(["a", "b"], ["a", "b"], "Array match")
    Assert.equals([1, "2"], [1, 2], "Array doesn't match") // Fails
    Assert.equals([{x:1}], [{x:1}], "Object array match") // Passes
    Assert.equals([{x:1}], [{x:2}], "Object array mismatch") // Fails
    -
    • Fails the test by throwing an error with the provided message. +This method is used to explicitly indicate that a test case has failed, +regardless of any conditions or assertions.

      Parameters

      • Optionalmessage: string

        (Optional) The failure message to display. -If not provided, a default "Assertion failed" message is used. -*

        -

      Returns void

      AssertionError - Always throws an AssertionError with the provided message.

      +If not provided, a default "Assertion failed" message is used.

      +

    Returns void

      +
    • This method never returns, it always throws an error.
    • +
    +

    AssertionError - Always throws an AssertionError with the provided message.

    Assert.fail("This test should not pass")
     
    -
    • Asserts that the given value is defined (not undefined). -Alias for isNotUndefined.

      +
    • Asserts that the given value is defined (not undefined). +Alias for isNotUndefined method.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to check.

      • message: string = ""

        (Optional) Message to prefix in case of failure.

        -

      Returns asserts value is Exclude<T, undefined>

      AssertionError - If the value is undefined.

      +

    Returns asserts value is Exclude<T, undefined>

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the value is undefined.

    Assert.isDefined(42, "Value should be defined")
    Assert.isDefined(null, "Null is allowed, but not undefined")
    Assert.isDefined(42)
    Assert.isDefined(null)
    -
      -
    • Assert.isNotUndefined for the opposite assertion.
    • -
    • Assert.isUndefined for an alias that checks for undefined values.
    • +
    -
    • Asserts that the provided value is falsy. Throws AssertionError if the value is not falsy.

      Parameters

      • value: unknown

        The value to test for falsiness.

      • message: string = ""

        (Optional) Message to prefix in case of failure.

        -

      Returns void

      AssertionError - If the value is not falsy.

      +

    Returns void

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the value is not falsy.

    Assert.isFalse(1 > 2, "Math sanity")
    Assert.isFalse(null, "Null should be falsy")
    Assert.isFalse(undefined, "Undefined should be falsy")
    Assert.isFalse(false, "Boolean false should be falsy")
    Assert.isFalse(0, "Zero should be falsy")
    Assert.isFalse("", "Empty string should be falsy")
    -

    Assert.isTrue for the opposite assertion.

    -
    • Asserts that the value is an instance of the specified constructor. -Throws AssertionError if not.

      +

      Assert.isTrue for the opposite assertion.

      +
    • Asserts that the value is an instance of the specified constructor. +Throws AssertionError if not.

      Parameters

      • value: unknown

        The value to check.

      • ctor: Function

        The class/constructor function.

      • message: string = ""

        Optional error message prefix.

        -

      Returns void

      AssertionError - If the value is not an instance of the constructor.

      +

    Returns void

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the value is not an instance of the constructor.

    class MyClass {}
    const instance = new MyClass()
    Assert.isInstanceOf(instance, MyClass, "Should be an instance of MyClass")
    Assert.isInstanceOf(instance, Object) // Passes, since all classes inherit from Object
    Assert.isInstanceOf(42, MyClass) // Fails
    -

    Assert.isNotInstanceOf for the opposite assertion.

    -
    • Asserts that the value is NOT an instance of the specified constructor. -Throws AssertionError if it is.

      +

      Assert.isNotInstanceOf for the opposite assertion.

      +
    • Asserts that the value is NOT an instance of the specified constructor. +Throws AssertionError if it is.

      Parameters

      • value: unknown

        The value to check.

      • ctor: Function

        The class/constructor function.

      • message: string = ""

        Optional error message prefix.

        -

      Returns void

      AssertionError - If the value is an instance of the constructor.

      +

    Returns void

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the value is an instance of the constructor.

    class MyClass {}
    const instance = new MyClass()
    Assert.isNotInstanceOf(instance, String, "Should not be an instance of String")
    Assert.isNotInstanceOf(instance, MyClass) // Fails
    Assert.isNotInstanceOf(42, MyClass) // Passes, since 42 is not an instance of MyClass
    -

    Assert.isInstanceOf for the opposite assertion.

    -
    • Asserts that the given value is not null. Provides a robust stringification of the value for error messages, guarding against unsafe or error-throwing toString() implementations. Narrows the type of 'value' to NonNullable if assertion passes.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to test.

      • message: string = ""

        Optional message to prefix in case of failure.

        -

      Returns asserts value is NonNullable<T>

      AssertionError if the value is null.

      +

    Returns asserts value is NonNullable<T>

      +
    • Narrows the type of 'value' to NonNullable if the assertion passes.
    • +
    +

    AssertionError if the value is null.

    Assert.isNotNull(42, "Value should not be null")
    Assert.isNotNull(null, "Value should be null") // Fails
    -
      -
    • Assert.isNull for the opposite assertion.
    • -
    • Assert.isDefined for an alias that checks for defined values (not null or undefined).
    • +
    +
    • Asserts that a value is NOT of the specified primitive type.

      +

      Parameters

      • value: unknown

        The value to check.

        +
      • type:
            | "string"
            | "number"
            | "bigint"
            | "boolean"
            | "symbol"
            | "undefined"
            | "object"
            | "function"

        The unwanted type as a string (string, number, etc.)

        +
      • message: string = ""

        Optional error message.

        +

      Returns void

        +
      • This method does not return a value.
      -
    • Asserts that the given value is not undefined. +

      AssertionError - If the type matches.

      +
      isNotType("hello", "number"); // passes
      isNotType(42, "string"); // passes
      isNotType({}, "object"); // throws
      isNotType(null, "object", "Should not be object"); // throws (null is object in JS) +
      + +

      This method checks the type using typeof and throws an AssertionError if the type matches. +The type parameter must be one of the following strings: string, number, boolean, object, function, undefined, symbol, or bigint.

      +

      Assert.isType for the positive assertion.

      +
    • Asserts that the given value is not undefined. Narrows the type to exclude undefined. -Throws AssertionError if the value is undefined.

      +Throws AssertionError if the value is undefined.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to check.

      • message: string = ""

        (Optional) Message to prefix in case of failure.

        -

      Returns asserts value is Exclude<T, undefined>

      AssertionError - If the value is undefined.

      -
      Assert.isNotUndefined(42, "Value should not be undefined")
      Assert.isNotUndefined(null, "Null is allowed, but not undefined")
      Assert.isNotUndefined(42)
      Assert.isNotUndefined(null) +

    Returns asserts value is Exclude<T, undefined>

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the value is undefined.

    +
    Assert.isNotUndefined(42, "Value should not be undefined")
    Assert.isNotUndefined(null, "Null is allowed, but not undefined")
    Assert.isNotUndefined(42)
    Assert.isNotUndefined(null)
    -
      -
    • Assert.isUndefined for the opposite assertion.
    • -
    • Assert.isDefined for an alias that checks for defined values (not undefined).
    • +
    -
    • Asserts that the given value is strictly null. +

    • Asserts that the given value is strictly null. Provides a robust stringification of the value for error messages, guarding against unsafe or error-throwing toString() implementations.

      Parameters

      • value: unknown

        The value to test.

      • message: string = ""

        Optional message to prefix in case of failure.

        -

      Returns asserts value is null

      AssertionError if the value is not exactly null. -*

      -
      Assert.isNull(null, "Value should be null")
      Assert.isNull(undefined, "Value should not be undefined") // Fails
      Assert.isNull(0, "Zero is not null") // Fails
      Assert.isNull(null)
      Assert.isNull(undefined) // Fails
      Assert.isNull(0) // Fails
      @see Assert.isDefined for an alias that checks for defined values (not `null` or `undefined` +

    Returns asserts value is null

      +
    • Narrows the type of 'value' to null if the assertion passes.
    • +
    +

    AssertionError if the value is not exactly null.

    +
    Assert.isNull(null, "Value should be null")
    Assert.isNull(undefined, "Value should not be undefined") // Fails
    Assert.isNull(0, "Zero is not null") // Fails
    Assert.isNull(null)
    Assert.isNull(undefined) // Fails
    Assert.isNull(0) // Fails
    -
    • Asserts that the provided value is truthy. +

      Assert.isDefined for an alias that checks for defined values (not null or undefined).

      +
    • Asserts that the provided value is truthy. Throws AssertionError if the value is not truthy.

      Parameters

      • value: unknown

        The value to test for truthiness.

      • message: string = ""

        (Optional) Message to prefix in case of failure.

        -

      Returns asserts value

      AssertionError - If the value is not truthy.

      -
      Assert.isTrue(1 < 2, "Math sanity")
      Assert.isTrue("non-empty string", "String should be truthy") +

    Returns asserts value

      +
    • Narrows the type of 'value' to its original type if the assertion passes.
    • +
    +

    AssertionError - If the value is not truthy.

    +
    Assert.isTrue(1 < 2, "Math sanity")
    Assert.isTrue("non-empty string", "String should be truthy")
    -

    Assert.isFalse for the opposite assertion.

    -
    • Asserts that a value is of the specified primitive type.

      +

      Assert.isFalse for the opposite assertion.

      +
    • Asserts that a value is of the specified primitive type.

      Parameters

      • value: unknown

        The value to check.

        -
      • type:
            | "string"
            | "number"
            | "bigint"
            | "boolean"
            | "symbol"
            | "undefined"
            | "object"
            | "function"

        The expected type as a string ("string", "number", etc.)

        +
      • type:
            | "string"
            | "number"
            | "bigint"
            | "boolean"
            | "symbol"
            | "undefined"
            | "object"
            | "function"

        The expected type as a string (string, number, etc.)

      • message: string = ""

        Optional error message.

        -

      Returns void

      AssertionError - If the type does not match.

      -
      isType("hello", "string"); // passes
      isType(42, "number"); // passes
      isType({}, "string"); // throws +

    Returns void

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If the type does not match.

    +
    isType("hello", "string"); // passes
    isType(42, "number"); // passes
    isType({}, "string"); // throws
    isType([], "object", "Expected an object"); // passes
    isType(null, "object", "Expected an object"); // throws
    -
    • Asserts that the given value is strictly undefined. +

      This method checks the type using typeof and throws an AssertionError if the type does not match. +It is useful for validating input types in functions or methods. +The type parameter must be one of the following strings: string, number, boolean, object, function, undefined, symbol, or bigint. +If the value is null, it will be considered an object, which is consistent with JavaScript's behavior.

      +

      Assert.isNotType for the opposite assertion.

      +
    • Asserts that the given value is strictly undefined. Throws AssertionError if the value is not exactly undefined.

      Parameters

      • value: unknown

        The value to check.

      • message: string = ""

        (Optional) Message to prefix in case of failure.

        -

      Returns asserts value is undefined

      AssertionError - If the value is not undefined.

      -
      Assert.isUndefined(void 0)
      Assert.isUndefined(undefined)
      Assert.isUndefined(null, "Null is not undefined") // Fails +

    Returns asserts value is undefined

      +
    • Narrows the type of 'value' to undefined if the assertion passes.
    • +
    +

    AssertionError - If the value is not undefined.

    +
    Assert.isUndefined(void 0)
    Assert.isUndefined(undefined)
    Assert.isUndefined(null, "Null is not undefined") // Fails
    -
      -
    • Assert.isNotUndefined for the opposite assertion.
    • -
    • Assert.isDefined for an alias that checks for defined values (not undefined).
    • +
    -
    • Asserts that two values are not equal (deep comparison). -For arrays and objects, uses deep comparison (via JSON.stringify). -Throws AssertionError if the values are equal.

      +
    • Asserts that two values are not equal (deep comparison). +For arrays and objects, uses deep comparison (via JSON.stringify). +Throws AssertionError if the values are equal.

      Type Parameters

      • T

      Parameters

      • actual: T

        The actual value.

      • notExpected: T

        The value that should NOT match.

      • message: string = ""

        (Optional) Message to prefix in case of failure.

        -

      Returns void

      AssertionError - If values are equal.

      -
      Assert.notEquals(1, 2, "Numbers should not be equal")
      Assert.notEquals([1, 2], [2, 1], "Arrays should not be equal")
      Assert.notEquals(1, 2)
      Assert.notEquals([1,2], [2,1])
      ```
      +

    Returns void

      +
    • This method does not return a value.
    • +
    +

    AssertionError - If values are equal.

    +
    Assert.notEquals(1, 2, "Numbers should not be equal")
    Assert.notEquals([1, 2], [2, 1], "Arrays should not be equal")
    Assert.notEquals({ a: 1 }, { a: 2 }, "Objects should not be equal")
    Assert.notEquals(1, 2)
    Assert.notEquals([1,2], [2,1])
    ```
    -
    • Asserts that the provided function throws an error. +

    • Asserts that the provided function throws an error. Optionally checks the error type and message.

      Parameters

      • fn: () => void

        A function that is expected to throw an error. -Must be passed as a function reference, e.g. '() => codeThatThrows()'.

        -
      • OptionalexpectedErrorType: Function

        (Optional) Expected constructor of the thrown error (e.g., 'TypeError').

        +Must be passed as a function reference, e.g. () => codeThatThrows().

        +
      • OptionalexpectedErrorType: Function

        (Optional) Expected constructor of the thrown error (e.g., TypeError).

      • OptionalexpectedMessage: string

        (Optional) Exact expected error message.

      • message: string = ""

        (Optional) Additional prefix for the error message if the assertion fails.

        -

      Returns asserts fn is () => never

      AssertionError - If no error is thrown, or if the thrown error does not match the expected type or message.

      -
      Assert.throws(() => {
      throw new TypeError("Invalid")
      }, TypeError, "Invalid", "Should throw TypeError") +

    Returns asserts fn is () => never

      +
    • Asserts that 'fn' will throw an error if the assertion passes.
    • +
    +

    AssertionError - If no error is thrown, or if the thrown error does not match the expected type or message.

    +
    Assert.throws(() => {
    throw new TypeError("Invalid")
    }, TypeError, "Invalid", "Should throw TypeError")
    -

    Assert.doesNotThrow for the opposite assertion.

    -
    +

    Assert.doesNotThrow for the opposite assertion.

    +
    diff --git a/docs/typedoc/classes/AssertionError.html b/docs/typedoc/classes/AssertionError.html index 5f7a8e5..2ad3daf 100644 --- a/docs/typedoc/classes/AssertionError.html +++ b/docs/typedoc/classes/AssertionError.html @@ -1,10 +1,9 @@ -AssertionError | officescripts-unit-testing-framework
    officescripts-unit-testing-framework
      Preparing search index...

      Class AssertionError

      AssertionError is a custom error type used to indicate assertion failures in tests or validation utilities.

      -

      This error is intended to be thrown by assertion methods (such as those in a custom Assert class) when a condition -that should always be true is found to be false. Using a specific AssertionError type allows for more precise +AssertionError | officescripts-unit-testing-framework

      officescripts-unit-testing-framework
        Preparing search index...

        Class AssertionError

        AssertionError is a custom error type used to indicate assertion failures in tests or validation utilities. +This error is intended to be thrown by assertion methods (such as those in a custom Assert class) when a condition +that should always be true is found to be false. Using a specific AssertionError type allows for more precise error handling and clearer reporting in test environments, as assertion failures can be easily distinguished from other kinds of runtime errors.

        -

        Typical usage:

        -
        if (actual !== expected) {
        throw new AssertionError(`Expected ${expected}, but got ${actual}`)
        } +
        if (actual !== expected) {
        throw new AssertionError(`Expected ${expected}, but got ${actual}`)
        }

        Features:

        @@ -14,21 +13,21 @@
      • Accepts a message parameter describing the assertion failure.
      • This class is intentionally simple—no extra methods or properties are added, to keep assertion failures clear and unambiguous.

        -

        Hierarchy

        • Error
          • AssertionError
        Index

        Constructors

        Hierarchy

        • Error
          • AssertionError
        Index

        Constructors

        • Parameters

          • message: string

          Returns AssertionError

        Properties

        message: string
        name: string
        stack?: string
        stackTraceLimit: number

        The Error.stackTraceLimit property specifies the number of stack frames +

        Constructors

        Properties

        message: string
        name: string
        stack?: string
        stackTraceLimit: number

        The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

        The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

        If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

        -

        Methods

        • Creates a .stack property on targetObject, which when accessed returns +

        Methods

        • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

          const myObject = {};
          Error.captureStackTrace(myObject);
          myObject.stack; // Similar to `new Error().stack` @@ -44,5 +43,5 @@
          function a() {
          b();
          }

          function b() {
          c();
          }

          function c() {
          // Create an error without stack trace to avoid calculating the stack trace twice.
          const { stackTraceLimit } = Error;
          Error.stackTraceLimit = 0;
          const error = new Error();
          Error.stackTraceLimit = stackTraceLimit;

          // Capture the stack trace above function b
          Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
          throw error;
          }

          a();
          -

          Parameters

          • targetObject: object
          • OptionalconstructorOpt: Function

          Returns void

        +

        Parameters

        • targetObject: object
        • OptionalconstructorOpt: Function

        Returns void

        diff --git a/docs/typedoc/classes/TestRunner.html b/docs/typedoc/classes/TestRunner.html index 269d083..8cbc6c4 100644 --- a/docs/typedoc/classes/TestRunner.html +++ b/docs/typedoc/classes/TestRunner.html @@ -1,21 +1,22 @@ TestRunner | officescripts-unit-testing-framework
        officescripts-unit-testing-framework
          Preparing search index...

          Class TestRunner

          A utility class for managing and running test cases with controlled console output. TestRunner' supports configurable verbosity levels and allows structured logging with indentation for better test output organization. It is primarily designed for -test cases using assertion methods (e.g., 'Assert.equals', 'Assert.throws'). -Verbosity can be set via the 'TestRunner.VERBOSITY': constant object (enum pattern)

          +test cases using assertion methods (e.g., Assert.equals, Assert.throws). +Verbosity can be set via the TestRunner.VERBOSITY: constant object (enum pattern)

            -
          • 'OFF' (0): No output
          • -
          • 'HEADER' (1): High-level section headers only
          • -
          • 'SECTION' (2): Full nested titles +
          • OFF (0): No output
          • +
          • HEADER (1): High-level section headers only
          • +
          • SECTION (2): Full nested titles
          • +
          • SUBSECTION (3): Detailed test case titles Verbosity level is incremental, i.e. allows all logging events with indentation level that is -lower or equal than TestRunner.VERBOSITY.
          • +lower or equal than TestRunner.VERBOSITY.
          const runner = new TestRunner()
          runner.exec("Simple Length Test", () => {
          Assert.equals("test".length, 4)
          })
          function sum(a: number, b: number): number {return a + b}
          const a = 1, b = 2;
          runner.exec("Sum Test", () => {
          Assert.equals(sum(a, b), 3) // test passed
          })

          // Example output (if verbosity is set to show headers):
          // ** START: Sum Test **
          // ** END: Sum Test **

          Test functions are expected to use Assert methods internally. If an assertion fails, the error will be caught and reported with context.

          -
          Index

          Constructors

          Index

          Constructors

          Properties

          Methods

          exec getVerbosity @@ -23,15 +24,23 @@ title

          Constructors

          • Constructs a 'TestRunner' with the specified verbosity level.

            Parameters

            • verbosity: 0 | 1 | 2 | 3 = TestRunner.DEFAULT_VERBOSITY

              One of the values from 'TestRunner.VERBOSITY' (default: 'HEADER')

              -

            Returns TestRunner

          Properties

          VERBOSITY: { HEADER: 1; OFF: 0; SECTION: 2; SUBSECTION: 3 } = ...

          Verbosity level

          -

          Methods

          • See detailed JSDoc in class documentation

            -

            Parameters

            • name: string
            • fn: () => void
            • indent: number = 2

            Returns void

          • Returns the current verbosity level.

            -

            Returns 0 | 1 | 2 | 3

          • Returns the corresonding string label for the verbosity level.

            -

            Returns string

          • Conditionally prints a title message based on the configured verbosity. +

          Returns TestRunner

          Properties

          VERBOSITY: { HEADER: 1; OFF: 0; SECTION: 2; SUBSECTION: 3 } = ...

          Verbosity level

          +

          Methods

          • See detailed JSDoc in class documentation

            +

            Parameters

            • name: string

              The name of the test case.

              +
            • fn: () => void

              The function containing the test logic. It should contain assertions using Assert methods.

              +
            • indent: number = 2

              Indentation level for the title (default: 2). The indentation level is indicated +with the number of suffix '*'.

              +

            Returns void

            AssertionError - If an assertion fails within the test function.

            +
            const runner = new TestRunner()
            runner.exec("My Test", () => {
            Assert.equals(1 + 1, 2)
            }) +
            + +
          • Conditionally prints a title message based on the configured verbosity. The title is prefixed and suffixed with '' characters for visual structure. The number of '' will depend on the indentation level, for 2 it shows '**' as prefix and suffix.

            Parameters

            • msg: string

              The message to display

            • indent: number = 1

              Indentation level (default: 1). The indentation level is indicated with the number of suffix '*'.

              -

            Returns void

          +

          Returns void

          diff --git a/src/unit-test-framework.ts b/src/unit-test-framework.ts index ee5e1f4..095eced 100644 --- a/src/unit-test-framework.ts +++ b/src/unit-test-framework.ts @@ -18,13 +18,13 @@ // #region AssertionError /** - * AssertionError is a custom error type used to indicate assertion failures in tests or validation utilities. + * `AssertionError` is a custom error type used to indicate assertion failures in tests or validation utilities. * This error is intended to be thrown by assertion methods (such as those in a custom Assert class) when a condition - * that should always be true is found to be false. Using a specific AssertionError type allows for more precise + * that should always be true is found to be false. Using a specific `AssertionError` type allows for more precise * error handling and clearer reporting in test environments, as assertion failures can be easily distinguished from * other kinds of runtime errors. * @example - * ```typescript + * ```ts * if (actual !== expected) { * throw new AssertionError(`Expected ${expected}, but got ${actual}`) * } @@ -58,10 +58,11 @@ class Assert { * Asserts that the provided function throws an error. * Optionally checks the error type and message. * @param fn - A function that is expected to throw an error. - * Must be passed as a function reference, e.g. '() => codeThatThrows()'. - * @param expectedErrorType - (Optional) Expected constructor of the thrown error (e.g., 'TypeError'). + * Must be passed as a function reference, e.g. `() => codeThatThrows()`. + * @param expectedErrorType - (Optional) Expected constructor of the thrown error (e.g., `TypeError`). * @param expectedMessage - (Optional) Exact expected error message. * @param message - (Optional) Additional prefix for the error message if the assertion fails. + * @returns {asserts fn is () => never} - Asserts that 'fn' will throw an error if the assertion passes. * @throws AssertionError - If no error is thrown, or if the thrown error does not match the expected type or message. * @example * ```ts @@ -69,7 +70,7 @@ class Assert { * throw new TypeError("Invalid") * }, TypeError, "Invalid", "Should throw TypeError") * ``` - * @see Assert.doesNotThrow for the opposite assertion. + * @see {@link Assert.doesNotThrow} for the opposite assertion. */ public static throws( fn: () => void, @@ -104,14 +105,15 @@ class Assert { /** * Asserts that two values are equal by type and value. * Supports comparison of primitive types, one-dimensional arrays of primitives, - * and one-dimensional arrays of objects (deep equality via JSON.stringify). + * and one-dimensional arrays of objects (deep equality via `JSON.stringify`). * If the values differ, a detailed error is thrown. * For arrays, mismatches include index, value, and type. - * For arrays of objects, a shallow comparison using JSON.stringify is performed. + * For arrays of objects, a shallow comparison using `JSON.stringify` is performed. * If a value cannot be stringified (e.g., due to circular references), it is treated as "[unprintable value]" in error messages and object equality checks. * @param actual - The actual value. * @param expected - The expected value. * @param message - (Optional) Prefix message included in the thrown error on failure. + * @returns {asserts actual is T} - Asserts that 'actual' is of type `T` if the assertion passes. * @throws AssertionError - If 'actual' and 'expected' are not equal. * @example * ```ts @@ -121,6 +123,7 @@ class Assert { * Assert.equals([{x:1}], [{x:1}], "Object array match") // Passes * Assert.equals([{x:1}], [{x:2}], "Object array mismatch") // Fails * ``` + * @see {@link Assert.notEquals} for the opposite assertion. */ public static equals(actual: T, expected: T, message: string = ""): asserts actual is T { const PREFIX = message ? `${message}: ` : ""; @@ -177,8 +180,9 @@ class Assert { * guarding against unsafe or error-throwing `toString()` implementations. * @param value - The value to test. * @param message - Optional message to prefix in case of failure. + * @returns {asserts value is null} - Narrows the type of 'value' to `null` if the assertion passes. * @throws AssertionError if the value is not exactly `null`. - * * @example + * @example * ```ts * Assert.isNull(null, "Value should be null") * Assert.isNull(undefined, "Value should not be undefined") // Fails @@ -187,7 +191,7 @@ class Assert { * Assert.isNull(undefined) // Fails * Assert.isNull(0) // Fails * ``` - * @see Assert.isDefined for an alias that checks for defined values (not `null` or `undefined`). + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `null` or `undefined`). */ public static isNull(value: unknown, message: string = ""): asserts value is null { const PREFIX = message ? `${message}: ` : "" @@ -207,14 +211,15 @@ class Assert { * Narrows the type of 'value' to NonNullable if assertion passes. * @param value - The value to test. * @param message - Optional message to prefix in case of failure. + * @returns {asserts value is NonNullable} - Narrows the type of 'value' to NonNullable if the assertion passes. * @throws AssertionError if the value is `null`. * @example * ```ts * Assert.isNotNull(42, "Value should not be null") * Assert.isNotNull(null, "Value should be null") // Fails * ``` - * @see Assert.isNull for the opposite assertion. - * @see Assert.isDefined for an alias that checks for defined values (not `null` or `undefined`). + * @see {@link Assert.isNull} for the opposite assertion. + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `null` or `undefined`). */ public static isNotNull(value: T, message: string = ""): asserts value is NonNullable { const PREFIX = message ? `${message}: ` : "" @@ -233,7 +238,8 @@ class Assert { * regardless of any conditions or assertions. * @param message - (Optional) The failure message to display. * If not provided, a default "Assertion failed" message is used. - * @throws AssertionError - Always throws an AssertionError with the provided message. + * @returns {never} - This method never returns, it always throws an error. + * @throws AssertionError - Always throws an `AssertionError` with the provided message. * @example * ```ts * Assert.fail("This test should not pass") @@ -248,8 +254,9 @@ class Assert { /** * Asserts that a value is of the specified primitive type. * @param value - The value to check. - * @param type - The expected type as a string ("string", "number", etc.) + * @param type - The expected type as a string (`string`, `number`, etc.) * @param message - Optional error message. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the type does not match. * @example * ```ts @@ -259,11 +266,11 @@ class Assert { * isType([], "object", "Expected an object"); // passes * isType(null, "object", "Expected an object"); // throws * ``` - * @remarks This method checks the type using `typeof` and throws an AssertionError if the type does not match. + * @remarks This method checks the type using `typeof` and throws an `AssertionError` if the type does not match. * It is useful for validating input types in functions or methods. - * The `type` parameter must be one of the following strings: "string", "number", "boolean", "object", "function", "undefined", "symbol", or "bigint". + * The `type` parameter must be one of the following strings: `string`, `number`, `boolean`, `object`, `function`, `undefined`, `symbol`, or `bigint`. * If the value is `null`, it will be considered an object, which is consistent with JavaScript's behavior. - * @see Assert.isNotType for the opposite assertion. + * @see {@link Assert.isNotType} for the opposite assertion. */ public static isType( value: unknown, @@ -283,8 +290,9 @@ class Assert { /** * Asserts that a value is NOT of the specified primitive type. * @param value - The value to check. - * @param type - The unwanted type as a string ("string", "number", etc.) + * @param type - The unwanted type as a string (`string`, `number`, etc.) * @param message - Optional error message. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the type matches. * @example * ```ts @@ -293,9 +301,9 @@ class Assert { * isNotType({}, "object"); // throws * isNotType(null, "object", "Should not be object"); // throws (null is object in JS) * ``` - * @remarks This method checks the type using `typeof` and throws an AssertionError if the type matches. - * The `type` parameter must be one of the following strings: "string", "number", "boolean", "object", "function", "undefined", "symbol", or "bigint". - * @see Assert.isType for the positive assertion. + * @remarks This method checks the type using `typeof` and throws an `AssertionError` if the type matches. + * The `type` parameter must be one of the following strings: `string`, `number`, `boolean`, `object`, `function`, `undefined`, `symbol`, or `bigint`. + * @see {@link Assert.isType} for the positive assertion. */ public static isNotType( value: unknown, @@ -314,10 +322,11 @@ public static isNotType( // #region doesNotThrow /** * Asserts that the provided function does NOT throw an error. - * If an error is thrown, an AssertionError is thrown with the provided message or details of the error. + * If an error is thrown, an `AssertionError` is thrown with the provided message or details of the error. * @param fn - A function that is expected to NOT throw. - * Must be passed as a function reference, e.g. '() => codeThatShouldNotThrow()'. + * Must be passed as a function reference, e.g. `() => codeThatShouldNotThrow()`. * @param message - (Optional) Prefix for the error message if the assertion fails. + * @return {void} - This method does not return a value. * @throws AssertionError - If the function throws any error. * @example * ```ts @@ -325,7 +334,7 @@ public static isNotType( * const x = 1 + 1 * }, "Should not throw any error") * ``` - * @see Assert.throws for the opposite assertion. + * @see {@link Assert.throws} for the opposite assertion. */ public static doesNotThrow(fn: () => void, message: string = ""): void { const PREFIX = message ? `${message}: ` : "" @@ -343,13 +352,14 @@ public static isNotType( * Throws AssertionError if the value is not truthy. * @param value - The value to test for truthiness. * @param message - (Optional) Message to prefix in case of failure. + * @returns {asserts value} - Narrows the type of 'value' to its original type if the assertion passes. * @throws AssertionError - If the value is not truthy. * @example * ```ts * Assert.isTrue(1 < 2, "Math sanity") * Assert.isTrue("non-empty string", "String should be truthy") * ``` - * @see Assert.isFalse for the opposite assertion. + * @see {@link Assert.isFalse} for the opposite assertion. */ public static isTrue(value: unknown, message: string = ""): asserts value { const PREFIX = message ? `${message}: ` : "" @@ -365,6 +375,7 @@ public static isNotType( * Throws AssertionError if the value is not falsy. * @param value - The value to test for falsiness. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the value is not falsy. * @example * ```ts @@ -375,7 +386,7 @@ public static isNotType( * Assert.isFalse(0, "Zero should be falsy") * Assert.isFalse("", "Empty string should be falsy") * ``` - * @see Assert.isTrue for the opposite assertion. + * @see {@link Assert.isTrue} for the opposite assertion. */ public static isFalse(value: unknown, message: string = ""): void { const PREFIX = message ? `${message}: ` : "" @@ -391,6 +402,7 @@ public static isNotType( * Throws AssertionError if the value is not exactly `undefined`. * @param value - The value to check. * @param message - (Optional) Message to prefix in case of failure. + * @returns {asserts value is undefined} - Narrows the type of 'value' to `undefined` if the assertion passes. * @throws AssertionError - If the value is not `undefined`. * @example * ```ts @@ -398,8 +410,8 @@ public static isNotType( * Assert.isUndefined(undefined) * Assert.isUndefined(null, "Null is not undefined") // Fails * ``` - * @see Assert.isNotUndefined for the opposite assertion. - * @see Assert.isDefined for an alias that checks for defined values (not `undefined`). + * @see {@link Assert.isNotUndefined} for the opposite assertion. + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `undefined`). */ public static isUndefined(value: unknown, message: string = ""): asserts value is undefined { const PREFIX = message ? `${message}: ` : "" @@ -413,9 +425,10 @@ public static isNotType( /** * Asserts that the given value is not `undefined`. * Narrows the type to exclude undefined. - * Throws AssertionError if the value is `undefined`. + * Throws `AssertionError` if the value is `undefined`. * @param value - The value to check. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the value is `undefined`. * @example * ```ts @@ -424,8 +437,8 @@ public static isNotType( * Assert.isNotUndefined(42) * Assert.isNotUndefined(null) * ``` - * @see Assert.isUndefined for the opposite assertion. - * @see Assert.isDefined for an alias that checks for defined values (not `undefined`). + * @see {@link Assert.isUndefined} for the opposite assertion. + * @see {@link Assert.isDefined} for an alias that checks for defined values (not `undefined`). */ public static isNotUndefined(value: T, message: string = ""): asserts value is Exclude { const PREFIX = message ? `${message}: ` : "" @@ -438,9 +451,10 @@ public static isNotType( // #region isDefined /** * Asserts that the given value is defined (not `undefined`). - * Alias for isNotUndefined. + * Alias for `isNotUndefined` method. * @param value - The value to check. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If the value is `undefined`. * @example * ```ts @@ -449,8 +463,8 @@ public static isNotType( * Assert.isDefined(42) * Assert.isDefined(null) * ``` - * @see Assert.isNotUndefined for the opposite assertion. - * @see Assert.isUndefined for an alias that checks for undefined values. + * @see {@link Assert.isNotUndefined} for the opposite assertion. + * @see {@link Assert.isUndefined} for an alias that checks for undefined values. */ public static isDefined(value: T, message: string = ""): asserts value is Exclude { Assert.isNotUndefined(value, message) @@ -460,11 +474,12 @@ public static isNotType( // #region notEquals /** * Asserts that two values are not equal (deep comparison). - * For arrays and objects, uses deep comparison (via JSON.stringify). - * Throws AssertionError if the values are equal. + * For arrays and objects, uses deep comparison (via `JSON.stringify`). + * Throws `AssertionError` if the values are equal. * @param actual - The actual value. * @param notExpected - The value that should NOT match. * @param message - (Optional) Message to prefix in case of failure. + * @returns {void} - This method does not return a value. * @throws AssertionError - If values are equal. * @example * ````ts @@ -474,7 +489,7 @@ public static isNotType( * Assert.notEquals(1, 2) * Assert.notEquals([1,2], [2,1]) * ``` - * @see Assert.equals for the opposite assertion. + * @see {@link Assert.equals} for the opposite assertion. */ public static notEquals(actual: T, notExpected: T, message: string = ""): void { const PREFIX = message ? `${message}: ` : "" @@ -490,12 +505,13 @@ public static isNotType( // #region contains /** * Asserts that an array or string contains a specified value or substring. - * For arrays, uses indexOf for shallow equality. - * For strings, uses indexOf for substring check. - * Throws AssertionError if the value is not found. + * For arrays, uses `indexOf` for shallow equality. + * For strings, uses `indexOf` for substring check. + * Throws `AssertionError` if the value is not found. * @param container - The array or string to search. * @param value - The value (or substring) to search for. * @param message - (Optional) Message to prefix in case of failure. + * @return {void} - This method does not return a value. * @throws AssertionError - If the value is not found. * @example * ```ts @@ -528,10 +544,11 @@ public static isNotType( // #region isInstanceOf /** * Asserts that the value is an instance of the specified constructor. - * Throws AssertionError if not. + * Throws `AssertionError` if not. * @param value - The value to check. * @param ctor - The class/constructor function. * @param message - Optional error message prefix. + * @return {void} - This method does not return a value. * @throws AssertionError - If the value is not an instance of the constructor. * @example * ```ts @@ -568,10 +585,11 @@ public static isNotType( // #region isNotInstanceOf /** * Asserts that the value is NOT an instance of the specified constructor. - * Throws AssertionError if it is. + * Throws `AssertionError` if it is. * @param value - The value to check. * @param ctor - The class/constructor function. * @param message - Optional error message prefix. + * @return {void} - This method does not return a value. * @throws AssertionError - If the value is an instance of the constructor. * @example * ```ts @@ -581,7 +599,7 @@ public static isNotType( * Assert.isNotInstanceOf(instance, MyClass) // Fails * Assert.isNotInstanceOf(42, MyClass) // Passes, since 42 is not an instance of MyClass * ``` - * @see Assert.isInstanceOf for the opposite assertion. + * @see {@link Assert.isInstanceOf} for the opposite assertion. */ public static isNotInstanceOf( value: unknown, @@ -608,6 +626,7 @@ public static isNotType( * @param a - Actual array. * @param b - Expected array. * @param message - (Optional) Prefix message for errors. + * @returns {boolean} - Returns true if arrays are equal, otherwise throws an error. * @throws AssertionError - If arrays differ in length, type, or value at any index. * @private */ @@ -647,8 +666,8 @@ public static isNotType( /** * Returns a safe string representation of any value, handling cases where * toString may throw or misbehave. Used internally by assertion methods. - * Tries JSON.stringify, then value.toString(), then Object.prototype.toString.call(value). - * If all fail, returns "[unprintable value]". + * Tries `JSON.stringify`, then `value.toString()`, then `Object.prototype.toString.call(value)`. + * If all fail, returns `[unprintable value]`. * @param value - The value to stringify. * @returns A string representation of the value, or "[unprintable value]" if not possible. * @private @@ -692,13 +711,14 @@ public static isNotType( * A utility class for managing and running test cases with controlled console output. * TestRunner' supports configurable verbosity levels and allows structured logging * with indentation for better test output organization. It is primarily designed for - * test cases using assertion methods (e.g., 'Assert.equals', 'Assert.throws'). - * Verbosity can be set via the 'TestRunner.VERBOSITY': constant object (enum pattern) - * - 'OFF' (0): No output - * - 'HEADER' (1): High-level section headers only - * - 'SECTION' (2): Full nested titles + * test cases using assertion methods (e.g., `Assert.equals`, `Assert.throws`). + * Verbosity can be set via the `TestRunner.VERBOSITY`: constant object (enum pattern) + * - `OFF` (0): No output + * - `HEADER` (1): High-level section headers only + * - `SECTION` (2): Full nested titles + * - `SUBSECTION` (3): Detailed test case titles * Verbosity level is incremental, i.e. allows all logging events with indentation level that is - * lower or equal than TestRunner.VERBOSITY. + * lower or equal than `TestRunner.VERBOSITY`. * * @example * ```ts @@ -721,9 +741,9 @@ public static isNotType( * the error will be caught and reported with context. */ class TestRunner { - private static readonly START = "START" as const; - private static readonly END = "END" as const; - private static readonly HEADER_TK = "*"; + private static readonly START = "START" as const + private static readonly END = "END" as const + private static readonly HEADER_TK = "*" /**Verbosity level */ public static readonly VERBOSITY = { diff --git a/test/main.ts b/test/main.ts index aae843e..4d16a9d 100644 --- a/test/main.ts +++ b/test/main.ts @@ -145,7 +145,7 @@ class AssertTest { Assert.isTrue(e.message === errMsg, "Did throw AssertionError but with wrong message for null") } if (!threw) { - throw new Error("Assert.isTrue(null) did not throw") + throw new Error("isTrue(null) did not throw") } // undefined @@ -156,12 +156,12 @@ class AssertTest { threw = true errMsg = "isTrue: undefined should fail isTrue: Expected value to be truthy, but got (undefined)" if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for undefined") + throw new Error("isTrue(undefined): Did not throw AssertionError for undefined") } - Assert.isTrue(e.message === errMsg, "Did throw AssertionError but with wrong message for undefined") + Assert.isTrue(e.message === errMsg, "isTrue(undefined): Did throw AssertionError but with wrong message for undefined") } if (!threw) { - throw new Error("Assert.isTrue(undefined) did not throw") + throw new Error("isTrue(undefined) did not throw") } // false @@ -172,12 +172,12 @@ class AssertTest { threw = true errMsg = "isTrue: false should fail isTrue: Expected value to be truthy, but got (false)" if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for false") + throw new Error("isTrue(false): Did not throw AssertionError for false") } - Assert.isTrue(e.message === errMsg, "Did throw AssertionError but with wrong message for false") + Assert.isTrue(e.message === errMsg, "isTrue(false): Did throw AssertionError but with wrong message for false") } if (!threw) { - throw new Error("Assert.isTrue(false) did not throw") + throw new Error("isTrue(false): did not throw") } // 0 @@ -188,28 +188,28 @@ class AssertTest { threw = true errMsg = "isTrue: 0 should fail isTrue: Expected value to be truthy, but got (0)" if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for 0") + throw new Error("isTrue(0): Did not throw AssertionError for 0") } - Assert.isTrue(e.message === errMsg, "Did throw AssertionError but with wrong message for 0") + Assert.isTrue(e.message === errMsg, "isTrue(0): Did throw AssertionError but with wrong message for 0") } if (!threw) { - throw new Error("Assert.isTrue(0) did not throw") + throw new Error("isTrue(0): did not throw") } // Empty string threw = false try { - Assert.isTrue("", "isTrue: '' should fail isTrue") + Assert.isTrue("", "isTrue(empty string): '' should fail isTrue") } catch (e) { threw = true - errMsg = "isTrue: '' should fail isTrue: Expected value to be truthy, but got (\"\")" + errMsg = "isTrue(empty string): '' should fail isTrue: Expected value to be truthy, but got (\"\")" if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for empty string") + throw new Error("isTrue(empty string): Did not throw AssertionError for empty string") } - Assert.isTrue(e.message === errMsg, "Did throw AssertionError but with wrong message for empty string") + Assert.isTrue(e.message === errMsg, "isTrue(empty string): Did throw AssertionError but with wrong message for empty string") } if (!threw) { - throw new Error("Assert.isTrue('') did not throw") + throw new Error("isTrue(empty string): did not throw") } } @@ -225,68 +225,68 @@ class AssertTest { // Negative: should throw for truthy values let threw = false try { - Assert.isFalse(true, "isFalse: true should fail") + Assert.isFalse(true, "isFalse(true): true should fail") } catch (e) { threw = true if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for true") + throw new Error("isFalse(true): Did not throw AssertionError for true") } } if (!threw) { - throw new Error("Assert.isFalse(true) did not throw") + throw new Error("isFalse(true): did not throw") } threw = false try { - Assert.isFalse(1, "isFalse: 1 should fail") + Assert.isFalse(1, "isFalse(1): 1 should fail") } catch (e) { threw = true if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for 1") + throw new Error("isFalse(1): Did not throw AssertionError for 1") } } if (!threw) { - throw new Error("Assert.isFalse(1) did not throw") + throw new Error("isFalse(1): did not throw") } threw = false try { - Assert.isFalse("non-empty", "isFalse: 'non-empty' should fail") + Assert.isFalse("non-empty", "isFalse(non-empty): 'non-empty' should fail") } catch (e) { threw = true if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for 'non-empty'") + throw new Error("isFalse(non-empty): Did not throw AssertionError for 'non-empty'") } } if (!threw) { - throw new Error("Assert.isFalse('non-empty') did not throw") + throw new Error("isFalse(non-empty): did not throw") } // Optional: add for [], {} threw = false try { - Assert.isFalse([], "isFalse: [] should fail") + Assert.isFalse([], "isFalse([]): [] should fail") } catch (e) { threw = true if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for []") + throw new Error("isFalse([]): Did not throw AssertionError for []") } } if (!threw) { - throw new Error("Assert.isFalse([]) did not throw") + throw new Error("isFalse([]): did not throw") } threw = false try { - Assert.isFalse({}, "isFalse: {} should fail") + Assert.isFalse({}, "isFalse({}): {} should fail") } catch (e) { threw = true if (!(e instanceof AssertionError)) { - throw new Error("Did not throw AssertionError for {}") + throw new Error("isFalse({}): Did not throw AssertionError for {}") } } if (!threw) { - throw new Error("Assert.isFalse({}) did not throw") + throw new Error("isFalse({}): did not throw") } } @@ -337,7 +337,7 @@ class AssertTest { Assert.isTrue(e instanceof AssertionError, "throws: did not throw AssertionError when function did not throw") } if (!threw) { - throw new Error("Assert.throws did not throw when function did not throw") + throw new Error("throws: did not throw when function did not throw") } // Negative: should throw AssertionError if the error type does not match @@ -354,7 +354,7 @@ class AssertTest { Assert.isTrue(e instanceof AssertionError, "throws: did not throw AssertionError when error type did not match") } if (!threw) { - throw new Error("Assert.throws did not throw when error type did not match") + throw new Error("throws: did not throw when error type did not match") } // Negative: should throw AssertionError if the error message does not match @@ -371,7 +371,7 @@ class AssertTest { Assert.isTrue(e instanceof AssertionError, "throws: did not throw AssertionError when error message did not match") } if (!threw) { - throw new Error("Assert.throws did not throw when error message did not match") + throw new Error("throws: did not throw when error message did not match") } // Negative: should throw AssertionError if thrown value is not an Error @@ -388,7 +388,7 @@ class AssertTest { Assert.isTrue(e instanceof AssertionError, "throws: did not throw AssertionError when thrown value was not Error") } if (!threw) { - throw new Error("Assert.throws did not throw when thrown value was not Error") + throw new Error("throws: did not throw when thrown value was not Error") } } @@ -416,7 +416,7 @@ class AssertTest { Assert.isTrue(e instanceof AssertionError, "doesNotThrow: did not throw AssertionError when function threw") } if (!threw) { - throw new Error("Assert.doesNotThrow did not throw when function threw") + throw new Error("doesNotThrow: did not throw when function threw") } // Negative: thrown value is not an Error (should still catch) @@ -431,7 +431,7 @@ class AssertTest { Assert.isTrue(e instanceof AssertionError, "doesNotThrow: did not throw AssertionError for non-Error thrown value") } if (!threw) { - throw new Error("Assert.doesNotThrow did not throw when thrown value was not Error") + throw new Error("doesNotThrow: did not throw when thrown value was not Error") } } @@ -514,32 +514,32 @@ class AssertTest { // Positive cases: should not throw for correct types Assert.doesNotThrow( () => { Assert.isType("hello", "string") }, - "assertType: should not throw for string" + "isType: should not throw for string" ) Assert.doesNotThrow( () => { Assert.isType(42, "number") }, - "assertType: should not throw for number" + "isType: should not throw for number" ) Assert.doesNotThrow( () => { Assert.isType(true, "boolean") }, - "assertType: should not throw for boolean" + "isType: should not throw for boolean" ) Assert.doesNotThrow( () => { Assert.isType({}, "object") }, - "assertType: should not throw for object" + "isType: should not throw for object" ) Assert.doesNotThrow( () => { Assert.isType(undefined, "undefined") }, - "assertType: should not throw for undefined" + "isType: should not throw for undefined" ) Assert.doesNotThrow( () => { Assert.isType(Symbol("s"), "symbol") }, - "assertType: should not throw for symbol" + "isType: should not throw for symbol" ) // Negative cases: should throw for wrong types @@ -547,72 +547,72 @@ class AssertTest { () => { Assert.isType("hello", "number") }, AssertionError, `Expected type 'number', but got 'string': ("hello")`, - "assertType: should throw for string as number" + "isType: should throw for string as number" ) Assert.throws( () => { Assert.isType(42, "string") }, AssertionError, `Expected type 'string', but got 'number': (42)`, - "assertType: should throw for number as string" + "isType: should throw for number as string" ) Assert.throws( () => { Assert.isType(false, "object") }, AssertionError, `Expected type 'object', but got 'boolean': (false)`, - "assertType: should throw for boolean as object" + "isType: should throw for boolean as object" ) Assert.throws( () => { Assert.isType({}, "number") }, AssertionError, `Expected type 'number', but got 'object': ({})`, - "assertType: should throw for object as number" + "isType: should throw for object as number" ) Assert.throws( () => { Assert.isType(undefined, "object") }, AssertionError, `Expected type 'object', but got 'undefined': (undefined)`, - "assertType: should throw for undefined as object" + "isType: should throw for undefined as object" ) } /** Test Assert.isNotType method. */ public static isNotType(): void { // Positive cases (should NOT throw) - Assert.isNotType("hello", "number", "String is not number") - Assert.isNotType(42, "string", "Number is not string") - Assert.isNotType(true, "object", "Boolean is not object") - Assert.isNotType(undefined, "boolean", "undefined is not boolean") - Assert.isNotType(Symbol("sym"), "number", "Symbol is not number") - Assert.isNotType(() => { }, "object", "Function is not object") + Assert.isNotType("hello", "number", "isNotType: String is not number") + Assert.isNotType(42, "string", "isNotType: Number is not string") + Assert.isNotType(true, "object", "isNotType: Boolean is not object") + Assert.isNotType(undefined, "boolean", "isNotType: undefined is not boolean") + Assert.isNotType(Symbol("sym"), "number", "isNotType: Symbol is not number") + Assert.isNotType(() => { }, "object", "isNotType: Function is not object") // Negative cases (should throw) Assert.throws( () => Assert.isNotType("test", "string"), AssertionError, undefined, - "Should throw: type matches string" + "isNotType: Should throw: type matches string" ) Assert.throws( () => Assert.isNotType(123, "number"), AssertionError, undefined, - "Should throw: type matches number" + "isNotType: Should throw: type matches number" ) Assert.throws( () => Assert.isNotType({}, "object"), AssertionError, undefined, - "Should throw: type matches object" + "isNotType: Should throw: type matches object" ) Assert.throws( () => Assert.isNotType(null, "object"), AssertionError, undefined, - "null is typeof object in JS" + "isNotType: null is typeof object in JS" ) } @@ -621,49 +621,49 @@ class AssertTest { // Positive: should not throw for equal numbers Assert.doesNotThrow( () => { Assert.equals(5, 5, "equals: numbers should match") }, - "equals: should not throw for equal numbers" + "equalsPrimitivesAndObjects: should not throw for equal numbers" ) // Positive: should not throw for equal strings Assert.doesNotThrow( () => { Assert.equals("abc", "abc", "equals: strings should match") }, - "equals: should not throw for equal strings" + "equalsPrimitivesAndObjects: should not throw for equal strings" ) // Positive: should not throw for equal booleans Assert.doesNotThrow( () => { Assert.equals(true, true, "equals: booleans should match") }, - "equals: should not throw for equal booleans" + "equalsPrimitivesAndObjects: should not throw for equal booleans" ) // Positive: should not throw for equal objects (deep, via JSON.stringify) Assert.doesNotThrow( () => { Assert.equals({ a: 1, b: "x" }, { a: 1, b: "x" }, "equals: objects should match") }, - "equals: should not throw for equal objects" + "equalsPrimitivesAndObjects: should not throw for equal objects" ) // Positive: should not throw for null equality Assert.doesNotThrow( () => { Assert.equals(null, null, "equals: nulls should match") }, - "equals: should not throw for null equality" + "equalsPrimitivesAndObjects: should not throw for null equality" ) // Positive: should not throw for equal arrays of numbers Assert.doesNotThrow( () => { Assert.equals([1, 2, 3], [1, 2, 3], "equals: arrays of numbers should match") }, - "equals: should not throw for equal arrays of numbers" + "equalsPrimitivesAndObjects: should not throw for equal arrays of numbers" ) // Positive: should not throw for equal arrays of objects Assert.doesNotThrow( () => { Assert.equals([{ x: 1 }, { y: 2 }], [{ x: 1 }, { y: 2 }], "equals: arrays of objects should match") }, - "equals: should not throw for equal arrays of objects" + "equalsPrimitivesAndObjects: should not throw for equal arrays of objects" ) // Positive: should not throw for nested arrays/objects Assert.doesNotThrow( () => { Assert.equals([{ a: [1, 2] }, { b: 3 }], [{ a: [1, 2] }, { b: 3 }], "equals: nested arrays/objects should match") }, - "equals: should not throw for nested arrays/objects equality" + "equalsPrimitivesAndObjects: should not throw for nested arrays/objects equality" ) // Negative: should throw for different numbers @@ -671,7 +671,7 @@ class AssertTest { () => { Assert.equals(5, 6, "equals: numbers should not match") }, AssertionError, "equals: numbers should not match: Assertion failed: actual (5 : number) !== expected (6 : number)", - "equals: should throw for different numbers" + "equalsPrimitivesAndObjects: should throw for different numbers" ) // Negative: should throw for different strings @@ -679,7 +679,7 @@ class AssertTest { () => { Assert.equals("abc", "def", "equals: strings should not match") }, AssertionError, "equals: strings should not match: Assertion failed: actual (\"abc\" : string) !== expected (\"def\" : string)", - "equals: should throw for different strings" + "equalsPrimitivesAndObjects: should throw for different strings" ) // Negative: should throw for different booleans @@ -687,7 +687,7 @@ class AssertTest { () => { Assert.equals(true, false, "equals: booleans should not match") }, AssertionError, "equals: booleans should not match: Assertion failed: actual (true : boolean) !== expected (false : boolean)", - "equals: should throw for different booleans" + "equalsPrimitivesAndObjects: should throw for different booleans" ) // Negative: should throw for different objects (deep, via JSON.stringify) @@ -695,7 +695,7 @@ class AssertTest { () => { Assert.equals({ a: 1, b: "x" }, { a: 2, b: "x" }, "equals: objects should not match") }, AssertionError, "equals: objects should not match: Assertion failed: actual ({\"a\":1,\"b\":\"x\"}) !== expected ({\"a\":2,\"b\":\"x\"})", - "equals: should throw for different objects" + "equalsPrimitivesAndObjects: should throw for different objects" ) // Negative: should throw for different arrays (length mismatch) @@ -703,7 +703,7 @@ class AssertTest { () => { Assert.equals([1, 2], [1, 2, 3], "equals: arrays length should not match") }, AssertionError, "equals: arrays length should not match: Array length mismatch: actual (2) !== expected (3)", - "equals: should throw for arrays with different lengths" + "equalsPrimitivesAndObjects: should throw for arrays with different lengths" ) // Negative: should throw for different arrays (element mismatch) @@ -711,7 +711,7 @@ class AssertTest { () => { Assert.equals([1, 2, 4], [1, 2, 3], "equals: arrays element should not match") }, AssertionError, "equals: arrays element should not match: Array value mismatch at index 2: actual (4) !== expected (3)", - "equals: should throw for arrays with different elements" + "equalsPrimitivesAndObjects: should throw for arrays with different elements" ) // Negative: should throw for arrays of objects (element mismatch) @@ -719,7 +719,7 @@ class AssertTest { () => { Assert.equals([{ x: 1 }], [{ x: 2 }], "equals: arrays of objects should not match") }, AssertionError, "equals: arrays of objects should not match: Array object value mismatch at index 0: actual ({\"x\":1}) !== expected ({\"x\":2})", - "equals: should throw for arrays of objects with different field values" + "equalsPrimitivesAndObjects: should throw for arrays of objects with different field values" ) // Negative: should throw for null vs undefined @@ -727,7 +727,7 @@ class AssertTest { () => { Assert.equals(null, undefined, "equals: null vs undefined should not match") }, AssertionError, "equals: null vs undefined should not match: Assertion failed: actual (null) !== expected (undefined)", - "equals: should throw for null vs undefined" + "equalsPrimitivesAndObjects: should throw for null vs undefined" ) // Negative: should throw for object vs array @@ -735,7 +735,7 @@ class AssertTest { () => { Assert.equals({ 0: 1 }, [1], "equals: object vs array should not match") }, AssertionError, "equals: object vs array should not match: Assertion failed: actual ({\"0\":1}) !== expected ([1])", - "equals: should throw for object vs array" + "equalsPrimitivesAndObjects: should throw for object vs array" ) // Negative: should throw for number vs string @@ -743,7 +743,7 @@ class AssertTest { () => { Assert.equals(1, "1", "equals: number vs string should not match") }, AssertionError, "equals: number vs string should not match: Assertion failed: actual (1 : number) !== expected (\"1\" : string)", - "equals: should throw for number vs string" + "equalsPrimitivesAndObjects: should throw for number vs string" ) // Negative: should throw for nested array/object value mismatch @@ -751,7 +751,7 @@ class AssertTest { () => { Assert.equals([{ a: [1, 2] }, { b: 3 }], [{ a: [1, 2] }, { b: 4 }], "equals: nested arrays/objects should not match") }, AssertionError, "equals: nested arrays/objects should not match: Array object value mismatch at index 1: actual ({\"b\":3}) !== expected ({\"b\":4})", - "equals: should throw for nested array/object value mismatch" + "equalsPrimitivesAndObjects: should throw for nested array/object value mismatch" ) } @@ -760,19 +760,19 @@ class AssertTest { // Positive: should not throw for equal number arrays Assert.doesNotThrow( () => { Assert.equals([1, 2, 3], [1, 2, 3], "equals: number arrays should match") }, - "equals: should not throw for equal number arrays" + "equalsArrays: should not throw for equal number arrays" ) // Positive: should not throw for equal string arrays Assert.doesNotThrow( () => { Assert.equals(["a", "b"], ["a", "b"], "equals: string arrays should match") }, - "equals: should not throw for equal string arrays" + "equalsArrays: should not throw for equal string arrays" ) // Positive: should not throw for arrays of equal objects Assert.doesNotThrow( () => { Assert.equals([{ x: 1 }, { y: 2 }], [{ x: 1 }, { y: 2 }], "equals: array of objects should match") }, - "equals: should not throw for equal array of objects" + "equalsArrays: should not throw for equal array of objects" ) // Negative: should throw for arrays with different lengths @@ -780,7 +780,7 @@ class AssertTest { () => { Assert.equals([1, 2], [1, 2, 3], "equals: arrays of different length") }, AssertionError, "equals: arrays of different length: Array length mismatch: actual (2) !== expected (3)", - "equals: should throw for arrays of different length" + "equalsArrays: should throw for arrays of different length" ) // Negative: should throw for arrays with different values @@ -788,7 +788,7 @@ class AssertTest { () => { Assert.equals([1, 2, 3], [1, 2, 4], "equals: arrays with one different value") }, AssertionError, "equals: arrays with one different value: Array value mismatch at index 2: actual (3) !== expected (4)", - "equals: should throw for arrays with different values" + "equalsArrays: should throw for arrays with different values" ) // Negative: should throw for arrays of objects with different values @@ -796,7 +796,7 @@ class AssertTest { () => { Assert.equals([{ x: 1 }], [{ x: 2 }], "equals: arrays of objects with different values") }, AssertionError, "equals: arrays of objects with different values: Array object value mismatch at index 0: actual ({\"x\":1}) !== expected ({\"x\":2})", - "equals: should throw for arrays of objects with different values" + "equalsArrays: should throw for arrays of objects with different values" ) // Negative: should throw for arrays with type mismatch @@ -804,7 +804,7 @@ class AssertTest { () => { Assert.equals([1, 2], ["1", "2"], "equals: arrays with type mismatch") }, AssertionError, "equals: arrays with type mismatch: Array type mismatch at index 0: actual (1 : number) !== expected (\"1\" : string)", - "equals: should throw for arrays with type mismatch" + "equalsArrays: should throw for arrays with type mismatch" ) } @@ -820,16 +820,16 @@ class AssertTest { // Inherited instance const b = new B() - Assert.isInstanceOf(b, A, "b should be instance of A (inherited)") - Assert.isInstanceOf(b, B, "b should be instance of B") + Assert.isInstanceOf(b, A, "isInstanceOf: b should be instance of A (inherited)") + Assert.isInstanceOf(b, B, "isInstanceOf: b should be instance of B") // Negative: instance of a different class const c = new C() Assert.throws( - () => Assert.isInstanceOf(c, A, "c should NOT be instance of A"), + () => Assert.isInstanceOf(c, A, "isInstanceOf: c should NOT be instance of A"), AssertionError, undefined, - "isInstanceOf: C is not A" + "isInstanceOf: isInstanceOf: C is not A" ) // Negative: primitive value is not an instance of any class @@ -876,15 +876,15 @@ class AssertTest { const z = new Z() // x should not be instance of Y or Z - Assert.isNotInstanceOf(x, Y, "x should NOT be instance of Y") - Assert.isNotInstanceOf(x, Z, "x should NOT be instance of Z") + Assert.isNotInstanceOf(x, Y, "isNotInstanceOf: x should NOT be instance of Y") + Assert.isNotInstanceOf(x, Z, "isNotInstanceOf: x should NOT be instance of Z") // b should not be instance of Z - Assert.isNotInstanceOf(y, Z, "y should NOT be instance of Z") + Assert.isNotInstanceOf(y, Z, "isNotInstanceOf: y should NOT be instance of Z") // z should not be instance of X or Y - Assert.isNotInstanceOf(z, X, "z should NOT be instance of X") - Assert.isNotInstanceOf(z, Y, "z should NOT be instance of Y") + Assert.isNotInstanceOf(z, X, "isNotInstanceOf: z should NOT be instance of X") + Assert.isNotInstanceOf(z, Y, "isNotInstanceOf: z should NOT be instance of Y") // Negative: x is instance of X Assert.throws( @@ -911,9 +911,9 @@ class AssertTest { ) // Non-object: primitives, null, undefined are never instances - Assert.isNotInstanceOf(null, X, "null should NOT be instance of X") - Assert.isNotInstanceOf(undefined, X, "undefined should NOT be instance of X") - Assert.isNotInstanceOf(123, X, "primitive should NOT be instance of X") + Assert.isNotInstanceOf(null, X, "isNotInstanceOf: null should NOT be instance of X") + Assert.isNotInstanceOf(undefined, X, "isNotInstanceOf: undefined should NOT be instance of X") + Assert.isNotInstanceOf(123, X, "isNotInstanceOf: primitive should NOT be instance of X") // Negative: constructor is not a function Assert.throws( @@ -926,114 +926,114 @@ class AssertTest { /** Test Assert.isUndefined method. */ public static isUndefined(): void { - Assert.isUndefined(undefined, "undefined is undefined") - Assert.isUndefined(void 0, "void 0 is undefined") + Assert.isUndefined(undefined, "isUndefined: undefined is undefined") + Assert.isUndefined(void 0, "isUndefined: void 0 is undefined") Assert.throws( () => Assert.isUndefined(null), AssertionError, undefined, - "null is not undefined" + "isUndefined: null is not undefined" ) Assert.throws( () => Assert.isUndefined(0), AssertionError, undefined, - "0 is not undefined" + "isUndefined: 0 is not undefined" ) Assert.throws( () => Assert.isUndefined(""), AssertionError, undefined, - "empty string is not undefined" + "isUndefined: empty string is not undefined" ) Assert.throws( () => Assert.isUndefined(false), AssertionError, undefined, - "false is not undefined" + "isUndefined: false is not undefined" ) } /** Test Assert.isNotUndefined and isDefined methods. */ public static isNotUndefined_and_isDefined(): void { - Assert.isNotUndefined(0, "0 is not undefined") - Assert.isNotUndefined(null, "null is not undefined") - Assert.isNotUndefined(false, "false is not undefined") - Assert.isDefined(1, "1 is defined") - Assert.isDefined("", "empty string is defined") - Assert.isDefined(null, "null is defined") + Assert.isNotUndefined(0, "isNotUndefined_and_isDefined: 0 is not undefined") + Assert.isNotUndefined(null, "isNotUndefined_and_isDefined: null is not undefined") + Assert.isNotUndefined(false, "isNotUndefined_and_isDefined: false is not undefined") + Assert.isDefined(1, "isNotUndefined_and_isDefined: 1 is defined") + Assert.isDefined("", "isNotUndefined_and_isDefined: empty string is defined") + Assert.isDefined(null, "isNotUndefined_and_isDefined: null is defined") Assert.throws( () => Assert.isNotUndefined(undefined), AssertionError, undefined, - "undefined should throw" + "isNotUndefined_and_isDefined: undefined should throw" ) Assert.throws( () => Assert.isDefined(undefined), AssertionError, undefined, - "undefined should throw" + "isNotUndefined_and_isDefined: undefined should throw" ) } /** Test Assert.notEquals method. */ public static notEquals(): void { - Assert.notEquals(1, 2, "1 !== 2") - Assert.notEquals("foo", "bar", "different strings") - Assert.notEquals([1, 2], [2, 1], "different arrays") - Assert.notEquals({ a: 1 }, { a: 2 }, "different objects") + Assert.notEquals(1, 2, "notEquals: 1 !== 2") + Assert.notEquals("foo", "bar", "notEquals: different strings") + Assert.notEquals([1, 2], [2, 1], "notEquals: different arrays") + Assert.notEquals({ a: 1 }, { a: 2 }, "notEquals: different objects") Assert.throws( () => Assert.notEquals(1, 1), AssertionError, undefined, - "1 == 1 should throw" + "notEquals: 1 == 1 should throw" ) Assert.throws( () => Assert.notEquals("abc", "abc"), AssertionError, undefined, - "identical strings" + "notEquals: identical strings" ) Assert.throws( () => Assert.notEquals(null, null), AssertionError, undefined, - "null == null" + "notEquals: null == null" ) Assert.throws( () => Assert.notEquals([1, 2], [1, 2]), AssertionError, undefined, - "equal arrays" + "notEquals: equal arrays" ) Assert.throws( () => Assert.notEquals({ x: 1 }, { x: 1 }), AssertionError, undefined, - "deep equal objects" + "notEquals: deep equal objects" ) } /** Test Assert.contains method for arrays and strings. */ public static contains(): void { // Array contains - Assert.contains([1, 2, 3], 2, "array contains 2") - Assert.contains(["a", "b"], "a", "array contains 'a'") + Assert.contains([1, 2, 3], 2, "contains: array contains 2") + Assert.contains(["a", "b"], "a", "contains: array contains 'a'") Assert.throws( () => Assert.contains([1, 2, 3], 4), AssertionError, undefined, - "array does not contain 4" + "contains: array does not contain 4" ) // String contains - Assert.contains("hello world", "world", "'hello world' contains 'world'") - Assert.contains("abc", "a", "'abc' contains 'a'") + Assert.contains("hello world", "world", "contains: 'hello world' contains 'world'") + Assert.contains("abc", "a", "contains: 'abc' contains 'a'") Assert.throws( () => Assert.contains("abc", "z"), AssertionError, undefined, - "'abc' does not contain 'z'" + "contains: 'abc' does not contain 'z'" ) // Error: not array or string @@ -1041,13 +1041,13 @@ class AssertTest { () => Assert.contains(123 as unknown as string, "1"), AssertionError, undefined, - "non-array/string container" + "contains: non-array/string container" ) Assert.throws( () => Assert.contains({ x: 1 } as unknown as string, "x"), AssertionError, undefined, - "object is not valid container" + "contains: object is not valid container" ) } @@ -1071,7 +1071,7 @@ class AssertSafeStringifyTest { () => { Assert.equals(obj, {}) }, AssertionError, undefined, - "safeStringify: should handle object with throwing toString" + "safeStringify(throwsToString): should handle object with throwing toString" ) } @@ -1081,7 +1081,7 @@ class AssertSafeStringifyTest { () => { Assert.isNotNull(null) }, AssertionError, 'Expected value not to be null, but got (null)', - "safeStringify: null should stringify to 'null'" + "safeStringify(null): null should stringify to 'null'" ) } @@ -1094,7 +1094,7 @@ class AssertSafeStringifyTest { () => { Assert.equals(a, {}) }, AssertionError, undefined, - "safeStringify: should handle circular reference" + "safeStringify(circularReference): should handle circular reference" ) } @@ -1106,7 +1106,7 @@ class AssertSafeStringifyTest { () => { Assert.isNull(sym) }, AssertionError, undefined, - "safeStringify: should handle symbol" + "safeStringify(symbolValue): should handle symbol" ) } @@ -1117,7 +1117,7 @@ class AssertSafeStringifyTest { () => { Assert.isNull(f) }, AssertionError, undefined, - "safeStringify: should handle function" + "safeStringify(functionValue): should handle function" ) } @@ -1127,7 +1127,7 @@ class AssertSafeStringifyTest { () => { Assert.isNull("abc") }, AssertionError, 'Expected value to be null, but got ("abc")', - "safeStringify: string should be quoted" + "safeStringify(stringIsQuoted): string should be quoted" ) } @@ -1137,25 +1137,25 @@ class AssertSafeStringifyTest { () => { Assert.isNull(0) }, AssertionError, 'Expected value to be null, but got (0)', - "safeStringify: should stringify 0" + "safeStringify(falsyValues): should stringify 0" ) Assert.throws( () => { Assert.isNull(false) }, AssertionError, 'Expected value to be null, but got (false)', - "safeStringify: should stringify false" + "safeStringify(falsyValues): should stringify false" ) Assert.throws( () => { Assert.isNull(undefined) }, AssertionError, 'Expected value to be null, but got (undefined)', - "safeStringify: should stringify undefined" + "safeStringify(falsyValues): should stringify undefined" ) Assert.throws( () => { Assert.isNull(NaN) }, AssertionError, 'Expected value to be null, but got (NaN)', - "safeStringify: should stringify NaN" + "safeStringify(falsyValues): should stringify NaN" ) } } @@ -1216,7 +1216,7 @@ class TestRunnerTest { runnerOff.title("This should not be visible", 1) runnerOff.title("This should not be visible either", 2) if (canCapture) { - Assert.equals(logs.length, 0, "runnerOff should not print any titles") + Assert.equals(logs.length, 0, "titlesAndExec: runnerOff should not print any titles") } // Should print only at indent 1 @@ -1224,8 +1224,8 @@ class TestRunnerTest { runnerHeader.title("Header Only", 1) runnerHeader.title("Section (should not print)", 2) if (canCapture) { - Assert.equals(logs.length, 1, "runnerHeader should print only one title") - Assert.isTrue(logs[0].indexOf("Header Only") !== -1, "runnerHeader output contains 'Header Only'") + Assert.equals(logs.length, 1, "titlesAndExec: runnerHeader should print only one title") + Assert.isTrue(logs[0].indexOf("Header Only") !== -1, "titlesAndExec: runnerHeader output contains 'Header Only'") } // Should print both @@ -1233,9 +1233,9 @@ class TestRunnerTest { runnerSection.title("Header", 1) runnerSection.title("Section", 2) if (canCapture) { - Assert.equals(logs.length, 2, "runnerSection should print two titles") - Assert.isTrue(logs[0].indexOf("Header") !== -1, "runnerSection output contains 'Header'") - Assert.isTrue(logs[1].indexOf("Section") !== -1, "runnerSection output contains 'Section'") + Assert.equals(logs.length, 2, "titlesAndExec: runnerSection should print two titles") + Assert.isTrue(logs[0].indexOf("Header") !== -1, "titlesAndExec: runnerSection output contains 'Header'") + Assert.isTrue(logs[1].indexOf("Section") !== -1, "titlesAndExec: runnerSection output contains 'Section'") } // Restore original log for exec tests (so you can see assertion output if running interactively) @@ -1245,7 +1245,7 @@ class TestRunnerTest { // Test exec with a simple passing function runnerHeader.exec("Exec Pass", () => { - Assert.equals(1, 1, "Exec should run this test") + Assert.equals(1, 1, "titlesAndExec: Exec should run this test") }, 2) // Test exec with a function that fails @@ -1253,7 +1253,7 @@ class TestRunnerTest { () => runnerHeader.exec("Exec Fail", () => Assert.equals(1, 2, "Should fail")), AssertionError, undefined, - "TestRunner.exec should propagate assertion errors" + "titlesAndExec: TestRunner.exec should propagate assertion errors" ) // Test exec with a non-function argument @@ -1261,7 +1261,7 @@ class TestRunnerTest { () => runnerHeader.exec("Not a function", null as unknown as () => void), AssertionError, undefined, - "TestRunner.exec should throw if input is not a function" + "titlesAndExec: TestRunner.exec should throw if input is not a function" ) // Always restore console.log (for safety) @@ -1273,9 +1273,9 @@ class TestRunnerTest { /** Test the getVerbosity and getVerbosityLabel methods of TestRunner. */ public static verbosityProperties(): void { const runner = new TestRunner(TestRunner.VERBOSITY.SECTION) - Assert.equals(runner.getVerbosity(), TestRunner.VERBOSITY.SECTION, "getVerbosity should return SECTION") - Assert.equals(runner.getVerbosityLabel(), "SECTION", "getVerbosityLabel should return 'SECTION'") - Assert.equals(runner.getVerbosityLabel(), "SUBSECTION", "getVerbosityLabel should return 'SUBSECTION'") + Assert.equals(runner.getVerbosity(), TestRunner.VERBOSITY.SECTION, "verbosityProperties: getVerbosity should return SECTION") + Assert.equals(runner.getVerbosityLabel(), "SECTION", "verbosityProperties: getVerbosityLabel should return 'SECTION'") + Assert.equals(runner.getVerbosityLabel(), "SUBSECTION", "verbosityProperties: getVerbosityLabel should return 'SUBSECTION'") } }