Throws an AssertionFailure with the given message if expr is falsy.
This method is used to assert that an expression evaluates to a truthy value.
The expression to evaluate. If the expression is falsy, an AssertionFailure is thrown.
OptionalinitMsg: MsgSourceThe message to display if expr is falsy. This can be a string or a function returning a string.
That the expr is truthy and throws AssertionFailure if it is not.
assert(true); // Passes
assert(1); // Passes
assert("a"); // Passes
assert([]); // Passes
assert({}); // Passes
assert(new Map()); // Passes
assert(new Set()); // Passes
assert(new Date()); // Passes
assert(false); // Throws AssertionFailure
assert(0); // Throws AssertionFailure
assert(""); // Throws AssertionFailure
assert(null); // Throws AssertionFailure
assert(undefined); // Throws AssertionFailure
Throws an AssertionFailure exception with then given message and includes
the actual and expected and operator in the properties of the exception.
This bypases the normal evaluation and will ALWAYS throw an exception, it does not
perform any evaluation.
The actual value
The expected value
OptionalfailMsg: MsgSourceThe optional message to include in the exception for the failure.
Optionaloperator: stringThe operator used in the evaluation
Readonly_Returns the last executed IScopeContext of the assertion chain of the immediately preceeding assertion operation. Does not support asynchronous operations as it is always overwritten by the last evaluated scope, used primarily to provide additional context for the error message during unexpected "pass" conditions.
Alias for closeTo. Asserts that the actual value is approximately equal to the expected value within the specified delta.
The actual value to check. Must be a number.
The expected value to compare against. Must be a number.
The maximum allowed difference between actual and expected. Must be a number. Note: A negative delta will never result in a passing assertion since the absolute difference is always non-negative.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function changes the monitored value. Can monitor either a getter function's return value or an object property.
The function to execute that should change the value.
A function that returns the value to monitor.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function changes the monitored value. Can monitor either a getter function's return value or an object property.
Asserts that the value DOES change but NOT by the specified delta after executing the target function. The value MUST change (cannot remain the same), but the change amount must not equal the specified delta. This differs from notChangesBy which allows the value to remain unchanged.
The function to execute that should change the value.
A function that returns the value to monitor.
The delta that should NOT match (sign is considered).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
let value = 0;
const getValue = () => value;
const addTwo = () => { value += 2; };
const noOp = () => {};
assert.changesButNotBy(addTwo, getValue, 5); // Passes - changed by 2, not by 5
assert.changesButNotBy(addTwo, getValue, 2); // Fails - changed by exactly 2
assert.changesButNotBy(noOp, getValue, 5); // Fails - no change occurred
Asserts that the property DOES change but NOT by the specified delta after executing the target function. The value MUST change (cannot remain the same), but the change amount must not equal the specified delta. This differs from notChangesBy which allows the value to remain unchanged.
The function to execute that should change the value.
An object containing the property to monitor.
The property name to monitor.
The delta that should NOT match (sign is considered).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
const obj = { count: 10 };
const addTwo = () => { obj.count += 2; };
const noOp = () => {};
assert.changesButNotBy(addTwo, obj, 'count', 5); // Passes - changed by 2, not by 5
assert.changesButNotBy(addTwo, obj, 'count', 2); // Fails - changed by exactly 2
assert.changesButNotBy(noOp, obj, 'count', 5); // Fails - no change occurred
Asserts that executing the target function changes the monitored value by the specified delta. Important: The sign of the delta is ignored - only the absolute value is compared. This means both positive and negative deltas with the same absolute value will match.
The function to execute that should change the value.
A function that returns the value to monitor.
The expected delta (sign is ignored, only absolute value matters).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
let value = 0;
const getValue = () => value;
const addFive = () => { value += 5; };
const subtractFive = () => { value -= 5; };
assert.changesBy(addFive, getValue, 5); // Passes (delta of +5)
assert.changesBy(addFive, getValue, -5); // Also passes (absolute value is 5)
assert.changesBy(subtractFive, getValue, 5); // Also passes (absolute value is 5)
Asserts that executing the target function changes the monitored object property by the specified delta. Important: The sign of the delta is ignored - only the absolute value is compared. This means both positive and negative deltas with the same absolute value will match.
The function to execute that should change the value.
An object containing the property to monitor.
The property name to monitor.
The expected delta (sign is ignored, only absolute value matters).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
const obj = { count: 10 };
const addFive = () => { obj.count += 5; };
const subtractFive = () => { obj.count -= 5; };
assert.changesBy(addFive, obj, 'count', 5); // Passes (delta of +5)
assert.changesBy(addFive, obj, 'count', -5); // Also passes (absolute value is 5)
assert.changesBy(subtractFive, obj, 'count', 5); // Also passes (absolute value is 5)
Asserts that the actual value is close to the expected value within the specified delta. This is useful for floating-point comparisons where exact equality is not guaranteed. The absolute difference between the actual and expected values must be less than or equal to delta.
The actual value to check. Must be a number.
The expected value to compare against. Must be a number.
The maximum allowed difference between actual and expected. Must be a number. Note: A negative delta will never result in a passing assertion since the absolute difference is always non-negative.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.closeTo(1.5, 1.0, 0.5); // Passes - difference is 0.5
assert.closeTo(10, 20, 20); // Passes - difference is 10
assert.closeTo(-10, 20, 30); // Passes - difference is 30
assert.closeTo(2, 1.0, 0.5); // Throws AssertionFailure - difference is 1.0
assert.closeTo(-10, 20, 29); // Throws AssertionFailure - difference is 30
Asserts that executing the target function decreases the monitored numeric value.
The function to execute that should decrease the value.
A function that returns the value to monitor.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function decreases the monitored object property.
Asserts that executing the target function decreases the monitored value but NOT by the specified delta. The value MUST decrease, but the decrease amount must not equal the specified delta.
The function to execute that should decrease the value.
A function that returns the value to monitor.
The delta that should NOT match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function decreases the monitored object property but NOT by the specified delta. The value MUST decrease, but the decrease amount must not equal the specified delta.
Asserts that executing the target function decreases the monitored value by the specified delta.
The function to execute that should decrease the value.
A function that returns the value to monitor.
The expected decrease delta (should be a positive value as a decrease is expected).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function decreases the monitored object property by the specified delta.
The function to execute that should decrease the value.
An object containing the property to monitor.
The property name to monitor.
The expected decrease delta (should be a positive value as a decrease is expected).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Performs a deep equality check between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
deeply equal to the expected value. This method compares the values of all properties
of objects and elements of arrays.
The type of the values.
That the actual and expected values are deeply equal and throws AssertionFailure if they are not.
assert.deepEqual({ a: 1 }, { a: 1 }); // Passes
assert.deepEqual({ a: 1 }, { a: 2 }); // Throws AssertionFailure
assert.deepEqual([1, 2], [1, 2]); // Passes
assert.deepEqual([1, 2], [2, 1]); // Throws AssertionFailure
assert.deepEqual({ a: { b: 1 } }, { a: { b: 1 } }); // Passes
assert.deepEqual({ a: { b: 1 } }, { a: { b: 2 } }); // Throws AssertionFailure
assert.deepEqual([{ a: 1 }], [{ a: 1 }]); // Passes
assert.deepEqual([{ a: 1 }], [{ a: 2 }]); // Throws AssertionFailure
Performs a deep equality check between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
deeply equal to the expected value. This method compares the values of all properties
of objects and elements of arrays.
The type of the values.
That the actual and expected values are deeply equal and throws AssertionFailure if they are not.
assert.deepEquals({ a: 1 }, { a: 1 }); // Passes
assert.deepEquals({ a: 1 }, { a: 2 }); // Throws AssertionFailure
assert.deepEquals([1, 2], [1, 2]); // Passes
assert.deepEquals([1, 2], [2, 1]); // Throws AssertionFailure
assert.deepEquals({ a: { b: 1 } }, { a: { b: 1 } }); // Passes
assert.deepEquals({ a: { b: 1 } }, { a: { b: 2 } }); // Throws AssertionFailure
assert.deepEquals([{ a: 1 }], [{ a: 1 }]); // Passes
assert.deepEquals([{ a: 1 }], [{ a: 2 }]); // Throws AssertionFailure
Asserts that the value contains the expected using deep nested property matching. Each property in the expected is deeply compared against the value.
That the value contains the match using deep nested property matching and throws AssertionFailure if it does not.
Asserts that the provided value has the specified nested property with a value that matches using deep equality.
That the value has the specified nested property with matching deep value and throws AssertionFailure if it does not.
assert.deepNestedProperty({ a: { b: { c: { d: 1 } } } }, "a.b.c"); // Passes
assert.deepNestedProperty({ a: { b: { c: { d: 1 } } } }, "a.b.c", { d: 1 }); // Passes
assert.deepNestedProperty({ a: { b: { c: [1, 2, 3] } } }, "a.b.c", [1, 2, 3]); // Passes
assert.deepNestedProperty({ a: { b: { c: { d: 1 } } } }, "a.b.c", { d: 2 }); // Throws AssertionFailure
Asserts that the value contains the expected using deep own property matching. For objects, checks that all keys in the expected are own properties (not inherited) and that values match using deep equality.
That the value deeply contains the expected using own property matching and throws AssertionFailure if it does not.
assert.deepOwnInclude({ a: { b: 1 } }, { a: { b: 1 } }); // Passes
assert.deepOwnInclude({ a: [1, 2, 3] }, { a: [1, 2, 3] }); // Passes
assert.deepOwnInclude({ a: { b: 1 } }, { a: { b: 2 } }); // Throws AssertionFailure
// Inherited properties are not matched:
const obj = Object.create({ inherited: { deep: 1 } });
obj.own = { deep: 2 };
assert.deepOwnInclude(obj, { own: { deep: 2 } }); // Passes
assert.deepOwnInclude(obj, { inherited: { deep: 1 } }); // Throws AssertionFailure
Performs a deep strict equality check between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
deeply strictly equal to the expected value. This method compares the values of all properties
of objects and elements of arrays, ensuring that both the values and their types are equal.
The type of the values.
That the actual and expected values are deeply and strictly equal and throws AssertionFailure if they are not.
assert.deepStrictEqual({ a: 1 }, { a: 1 }); // Passes
assert.deepStrictEqual({ a: 1 }, { a: "1" }); // Throws AssertionFailure
assert.deepStrictEqual([1, 2], [1, 2]); // Passes
assert.deepStrictEqual([1, 2], [2, 1]); // Throws AssertionFailure
assert.deepStrictEqual({ a: { b: 1 } }, { a: { b: 1 } }); // Passes
assert.deepStrictEqual({ a: { b: 1 } }, { a: { b: "1" } }); // Throws AssertionFailure
assert.deepStrictEqual([{ a: 1 }], [{ a: 1 }]); // Passes
assert.deepStrictEqual([{ a: 1 }], [{ a: "1" }]); // Throws AssertionFailure
Performs a deep strict equality check between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
deeply strictly equal to the expected value. This method compares the values of all properties
of objects and elements of arrays, ensuring that both the values and their types are equal.
The type of the values.
That the actual and expected values are deeply and strictly equal and throws AssertionFailure if they are not.
assert.deepStrictEquals({ a: 1 }, { a: 1 }); // Passes
assert.deepStrictEquals({ a: 1 }, { a: "1" }); // Throws AssertionFailure
assert.deepStrictEquals([1, 2], [1, 2]); // Passes
assert.deepStrictEquals([1, 2], [2, 1]); // Throws AssertionFailure
assert.deepStrictEquals({ a: { b: 1 } }, { a: { b: 1 } }); // Passes
assert.deepStrictEquals({ a: { b: 1 } }, { a: { b: "1" } }); // Throws AssertionFailure
assert.deepStrictEquals([{ a: 1 }], [{ a: 1 }]); // Passes
assert.deepStrictEquals([{ a: 1 }], [{ a: "1" }]); // Throws AssertionFailure
Asserts that the target collection contains a subsequence matching the expected members using deep equality. The members must appear in the specified order but don't need to be consecutive - other elements can appear between them. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should contain the ordered subsequence (must be an ArrayLikeOrSizedIterable).
The expected ordered subsequence (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function does NOT change the monitored value. This is the inverse of changes.
The function to execute.
A function that returns the value to monitor.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function does NOT change the monitored object property. This is the inverse of changes.
Asserts that executing the target function does NOT decrease the monitored numeric value. This is the inverse of decreases.
The function to execute.
A function that returns the value to monitor.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function does NOT decrease the monitored object property. This is the inverse of decreases.
Asserts that the target does NOT have all of the specified keys using deep equality comparison. This method checks that at least one of the given keys does not exist in the target using deep equality for key comparison. This is the inverse of hasAllDeepKeys.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target does not have all of the specified keys and throws AssertionFailure if it does.
const obj = { greeting: "hello", subject: "friend" };
assert.doesNotHaveAllDeepKeys(obj, "unknown"); // Passes - missing "unknown"
assert.doesNotHaveAllDeepKeys(obj, ["greeting", "unknown"]); // Passes - missing "unknown"
const map = new Map([[{ id: 1 }, "value1"]]);
assert.doesNotHaveAllDeepKeys(map, [{ id: 1 }, { id: 2 }]); // Passes - missing { id: 2 }
assert.doesNotHaveAllDeepKeys(obj, ["greeting", "subject"]); // Throws AssertionFailure - has both keys
Asserts that the target does NOT have all of the specified keys. This method checks that at least one of the given keys does not exist in the target. This is the inverse of hasAllKeys.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target does not have all of the specified keys and throws AssertionFailure if it does.
const obj = { greeting: "hello", subject: "friend" };
assert.doesNotHaveAllKeys(obj, "unknown"); // Passes - missing "unknown"
assert.doesNotHaveAllKeys(obj, ["greeting", "unknown"]); // Passes - missing "unknown"
assert.doesNotHaveAllKeys(obj, ["greeting", "subject"]); // Throws AssertionFailure - has both keys
const map = new Map([["a", 1], ["b", 2]]);
assert.doesNotHaveAllKeys(map, ["a", "c"]); // Passes - missing "c"
Asserts that the target does NOT have any of the specified keys using deep equality comparison. This method checks that none of the given keys exist in the target using deep equality for key comparison. This is the inverse of hasAnyDeepKeys.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target does not have any of the specified keys and throws AssertionFailure if it does.
const obj = { greeting: "hello", subject: "friend" };
assert.doesNotHaveAnyDeepKeys(obj, "unknown"); // Passes - does not have the key
assert.doesNotHaveAnyDeepKeys(obj, ["unknown", "missing"]); // Passes - has neither key
const map = new Map([[{ id: 1 }, "value1"]]);
assert.doesNotHaveAnyDeepKeys(map, [{ id: 3 }, { id: 4 }]); // Passes - has neither key
assert.doesNotHaveAnyDeepKeys(obj, ["greeting", "unknown"]); // Throws AssertionFailure - has "greeting"
Asserts that the target does NOT have any of the specified keys. This method checks that none of the given keys exist in the target. This is the inverse of hasAnyKeys.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target does not have any of the specified keys and throws AssertionFailure if it does.
const obj = { greeting: "hello", subject: "friend" };
assert.doesNotHaveAnyKeys(obj, "unknown"); // Passes - does not have the key
assert.doesNotHaveAnyKeys(obj, ["unknown", "missing"]); // Passes - has neither key
assert.doesNotHaveAnyKeys(obj, ["greeting", "unknown"]); // Throws AssertionFailure - has "greeting"
const map = new Map([["a", 1], ["b", 2]]);
assert.doesNotHaveAnyKeys(map, ["c", "d"]); // Passes - has neither key
Asserts that executing the target function does NOT increase the monitored numeric value. This is the inverse of increases.
The function to execute.
A function that returns the value to monitor.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function does NOT increase the monitored object property. This is the inverse of increases.
Asserts that the given function does NOT throw an error. Optionally checks that if an error is thrown, it does not match the specified error constructor or message pattern. If the function throws an error (that matches the optional criteria), it throws an AssertionFailure with the given message. This is the inverse of throws.
The function to execute and check for thrown errors.
OptionalerrorLike: Error | ErrorConstructorOptional. The error constructor or error instance that should NOT be thrown.
OptionalmsgMatch: string | RegExpOptional. The partial message or pattern that should NOT match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the function does not throw an error (or does not throw a matching error) and throws AssertionFailure if it does.
assert.doesNotThrow(() => {}); // Passes - no error thrown
assert.doesNotThrow(() => { return 42; }); // Passes - no error thrown
assert.doesNotThrow(() => { throw new Error("test"); }); // Throws AssertionFailure
assert.doesNotThrow(() => { throw new TypeError("test"); }); // Throws AssertionFailure
Asserts that the given function does NOT throw an error with a message matching the pattern. If the function throws an error with a matching message, it throws an AssertionFailure with the given message. This is the inverse of throws.
The function to execute and check for thrown errors.
OptionalmsgMatch: string | RegExpOptional. The partial message or pattern that should NOT match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the function does not throw an error with a matching message and throws AssertionFailure if it does.
Asserts that the target collection ends with the expected members in consecutive order at the end. Uses deep equality for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should end with the expected sequence (must be an ArrayLikeOrSizedIterable).
The expected ending sequence (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the target collection ends with the expected members in consecutive order at the end. Uses strict equality (===) for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should end with the expected sequence (must be an ArrayLikeOrSizedIterable).
The expected ending sequence (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Performs a loose equality check (==) between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
equal to the expected value. To perform a strict equality check (===), use the
assert.strictEqual method.
The type of the values.
That the actual and expected values are loosely (==) equal and throws AssertionFailure if they are not.
assert.equal(1, 1); // Passes
assert.equal(1, "1"); // Passes
assert.equal(1, 2); // Throws AssertionFailure
assert.equal("a", "a"); // Passes
assert.equal("a", "b"); // Throws AssertionFailure
assert.equal([1, 2], [1, 2]); // Throws AssertionFailure
assert.equal({ a: 1 }, { a: 1 }); // Throws AssertionFailure
assert.equal({ a: 1 }, { a: 1 }, "Objects are not equal"); // Throws AssertionFailure
assert.equal({ a: 1 }, { a: 2 }); // Throws AssertionFailure
assert.equal({ a: 1 }, { a: 2 }, "Objects are not equal"); // Throws AssertionFailure
assert.equal({ a: 1 }, { b: 1 }); // Throws AssertionFailure
assert.equal({ a: 1 }, { b: 1 }, "Objects are not equal"); // Throws AssertionFailure
assert.equal({ a: 1 }, { b: 2 }); // Throws AssertionFailure
assert.equal({ a: 1 }, { b: 2 }, "Objects are not equal"); // Throws AssertionFailure
Performs a loose equality check (==) between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
equal to the expected value. To perform a strict equality check (===), use the
assert.strictEqual method.
The type of the value.
That the actual and expected values are loosely (==) equal and throws AssertionFailure if they are not.
assert.equals(1, 1); // Passes
assert.equals(1, "1"); // Passes
assert.equals(1, 2); // Throws AssertionFailure
assert.equals("a", "a"); // Passes
assert.equals("a", "b"); // Throws AssertionFailure
assert.equals([1, 2], [1, 2]); // Throws AssertionFailure
assert.equals({ a: 1 }, { a: 1 }); // Throws AssertionFailure
assert.equals({ a: 1 }, { a: 1 }, "Objects are not equal"); // Throws AssertionFailure
assert.equals({ a: 1 }, { a: 2 }); // Throws AssertionFailure
assert.equals({ a: 1 }, { a: 2 }, "Objects are not equal"); // Throws AssertionFailure
assert.equals({ a: 1 }, { b: 1 }); // Throws AssertionFailure
assert.equals({ a: 1 }, { b: 1 }, "Objects are not equal"); // Throws AssertionFailure
assert.equals({ a: 1 }, { b: 2 }); // Throws AssertionFailure
assert.equals({ a: 1 }, { b: 2 }, "Objects are not equal"); // Throws AssertionFailure
Asserts that the given value exists (is not null and not undefined).
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not null and not undefined and throws AssertionFailure if it is.
assert.exists(0); // Passes - 0 is not null or undefined
assert.exists(""); // Passes - empty string exists
assert.exists(false); // Passes - false exists
assert.exists([]); // Passes - arrays exist
assert.exists({}); // Passes - objects exist
assert.exists(null); // Throws AssertionFailure
assert.exists(undefined); // Throws AssertionFailure
Throws an AssertionFailure with the given message. This method is used to explicitly fail an assertion with a custom message.
OptionalinitMsg: MsgSourceThe message to display. This can be a string or a function returning a string.
AssertionFailure - Always.
Throws an AssertionFailure with the given message and optional details
which are obtained via the getDetails function.
The actual value that was expected
The expected value that was not found
OptionalfailMsg: MsgSourceThe message to display.
Optionaloperator: stringThe optional operator used in the comparison
AssertionFailure always
Throws an AssertionFatal with the given message. This method is used to explicitly fail an assertion with a custom message.
OptionalinitMsg: MsgSourceThe message to display. This can be a string or a function returning a string.
AssertionFatal - Always.
Asserts that the target has all of the specified keys using deep equality comparison. This method checks if all of the given keys exist in the target using deep equality for key comparison. Particularly useful for Maps and Sets where keys may be objects.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target has all of the specified keys and throws AssertionFailure if it does not.
const obj = { greeting: "hello", subject: "friend", message: "darkness" };
assert.hasAllDeepKeys(obj, "greeting"); // Passes - has the key
assert.hasAllDeepKeys(obj, ["greeting", "subject"]); // Passes - has both keys
const map = new Map([[{ id: 1 }, "value1"], [{ id: 2 }, "value2"]]);
assert.hasAllDeepKeys(map, [{ id: 1 }, { id: 2 }]); // Passes - has both keys
assert.hasAllDeepKeys(obj, ["greeting", "unknown"]); // Throws AssertionFailure - missing "unknown"
Asserts that the target has all of the specified keys. This method checks if all of the given keys exist in the target. Works with objects, Maps, and Sets.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target has all of the specified keys and throws AssertionFailure if it does not.
const obj = { greeting: "hello", subject: "friend", message: "darkness" };
assert.hasAllKeys(obj, "greeting"); // Passes - has the key
assert.hasAllKeys(obj, ["greeting", "subject"]); // Passes - has both keys
assert.hasAllKeys(obj, ["greeting", "unknown"]); // Throws AssertionFailure - missing "unknown"
const map = new Map([["a", 1], ["b", 2]]);
assert.hasAllKeys(map, ["a", "b"]); // Passes - has both keys
Asserts that the target has any of the specified keys using deep equality comparison. This method checks if at least one of the given keys exists in the target using deep equality for key comparison. Particularly useful for Maps and Sets where keys may be objects.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target has at least one of the specified keys and throws AssertionFailure if it does not.
const obj = { greeting: "hello", subject: "friend" };
assert.hasAnyDeepKeys(obj, "greeting"); // Passes - has "greeting"
assert.hasAnyDeepKeys(obj, ["greeting", "message"]); // Passes - has "greeting"
const map = new Map([[{ id: 1 }, "value1"], [{ id: 2 }, "value2"]]);
assert.hasAnyDeepKeys(map, { id: 1 }); // Passes - deep key match
assert.hasAnyDeepKeys(map, [{ id: 1 }, { id: 3 }]); // Passes - has { id: 1 }
assert.hasAnyDeepKeys(obj, ["unknown", "missing"]); // Throws AssertionFailure
Asserts that the target has any of the specified keys. This method checks if at least one of the given keys exists in the target. Works with objects, Maps, and Sets.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target has at least one of the specified keys and throws AssertionFailure if it does not.
const obj = { greeting: "hello", subject: "friend" };
assert.hasAnyKeys(obj, "greeting"); // Passes - has "greeting"
assert.hasAnyKeys(obj, ["greeting", "message"]); // Passes - has "greeting"
assert.hasAnyKeys(obj, ["unknown", "missing"]); // Throws AssertionFailure
const map = new Map([["a", 1], ["b", 2]]);
assert.hasAnyKeys(map, "a"); // Passes - has "a"
assert.hasAnyKeys(map, ["a", "c"]); // Passes - has "a"
Asserts that the provided value has the specified own property with a value that matches using deep equality. If the value does not have the own property or the deep value doesn't match, it throws an AssertionFailure with the given message.
That the value has the specified own property with matching deep value and throws AssertionFailure if it does not.
Asserts that the provided value has the specified property with a value that matches using deep equality. If the value does not have the property or the deep value doesn't match, it throws an AssertionFailure with the given message.
That the value has the specified property with matching deep value and throws AssertionFailure if it does not.
Asserts that the provided value has the specified own property (i.e., a property that is not inherited). Optionally checks the property value using loose equality (==). If the value does not have the own property or the value doesn't match, it throws an AssertionFailure with the given message.
That the value has the specified own property and throws AssertionFailure if it does not.
assert.hasOwnProperty({ a: 1, b: 2 }, "a"); // Passes
assert.hasOwnProperty({ a: 1, b: 2 }, "c"); // Throws AssertionFailure
assert.hasOwnProperty(Object.create({ a: 1 }), "a"); // Throws AssertionFailure
assert.hasOwnProperty({ a: 1 }, "a", 1); // Passes
assert.hasOwnProperty({ a: 1 }, "a", 2); // Throws AssertionFailure
Asserts that the provided value has the specified property. Optionally checks the property value using loose equality (==). If the value does not have the property or the value doesn't match, it throws an AssertionFailure with the given message.
That the value has the specified property and throws AssertionFailure if it does not.
assert.hasProperty({ a: 1, b: 2 }, "a"); // Passes
assert.hasProperty({ a: 1, b: 2 }, "c"); // Throws AssertionFailure
assert.hasProperty({ a: 1 }, "a", 1); // Passes
assert.hasProperty({ a: 1 }, "a", "1"); // Passes (loose equality)
assert.hasProperty({ a: 1 }, "a", 2); // Throws AssertionFailure
Asserts that the target is falsy or throws the error if it is an Error instance. This is commonly used in Node.js-style callback error handling to check for errors.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.ifError(null); // Passes - null is falsy
assert.ifError(undefined); // Passes - undefined is falsy
assert.ifError(false); // Passes - false is falsy
assert.ifError(0); // Passes - 0 is falsy
assert.ifError(""); // Passes - empty string is falsy
// Throws the error itself
assert.ifError(new Error("Something went wrong"));
// Throws AssertionFailure
assert.ifError(true); // Truthy but not an Error
assert.ifError("error"); // Truthy but not an Error
assert.ifError(1); // Truthy but not an Error
Asserts that the superset collection includes all members of the subset collection (order doesn't matter). Uses deep equality for comparison. Particularly useful for Maps which iterate over [key, value] pairs. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should contain all members of the subset (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.includeDeepMembers([{a: 1}, {b: 2}], [{a: 1}]); // Passes
assert.includeDeepMembers([[1, 2], [3, 4]], [[1, 2]]); // Passes
assert.includeDeepMembers([{a: 1}, {b: 2}], new Set([{a: 1}])); // Passes - Array vs Set
assert.includeDeepMembers(new Set([{a: 1}, {b: 2}]), [{a: 1}]); // Passes - Set vs Array
// Maps iterate over [key, value] pairs
const map = new Map([[1, "a"], [2, "b"], [3, "c"]]);
assert.includeDeepMembers(map, [[1, "a"], [2, "b"]]); // Passes
assert.includeDeepMembers([{a: 1}], [{a: 2}]); // Throws AssertionFailure
Asserts that the superset collection includes all members of the subset collection in the same order (but may have additional members in between). Uses deep equality for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should contain all members of the subset (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the superset collection includes all members of the subset collection (order doesn't matter). Uses strict equality (===) for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should contain all members of the subset (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.includeMembers([1, 2, 3, 4], [2, 3]); // Passes - all members present
assert.includeMembers([1, 2, 3, 4], new Set([2, 3])); // Passes - Array vs Set
assert.includeMembers(new Set([1, 2, 3, 4]), [2, 3]); // Passes - Set vs Array
assert.includeMembers(new Set([1, 2, 3, 4]), new Set([2, 3])); // Passes - Set vs Set
assert.includeMembers([1, 2, 3], [1, 4]); // Throws AssertionFailure - 4 not present
Asserts that the superset collection includes all members of the subset collection in the same order (but may have additional members in between). Uses strict equality (===) for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should contain all members of the subset (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the provided value includes the specified match. The value can be
a string, array, or any other type that supports the includes method. If the
value does not include the match, it throws an AssertionFailure with the given message.
That the value includes the match and throws AssertionFailure if it does not.
Asserts that executing the target function increases the monitored numeric value.
The function to execute that should increase the value.
A function that returns the value to monitor.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function increases the monitored object property.
Asserts that executing the target function increases the monitored value but NOT by the specified delta. The value MUST increase, but the increase amount must not equal the specified delta.
The function to execute that should increase the value.
A function that returns the value to monitor.
The delta that should NOT match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function increases the monitored object property but NOT by the specified delta. The value MUST increase, but the increase amount must not equal the specified delta.
Asserts that executing the target function increases the monitored value by the specified delta.
The function to execute that should increase the value.
A function that returns the value to monitor.
The expected increase delta (must be positive).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function increases the monitored object property by the specified delta.
The function to execute that should increase the value.
An object containing the property to monitor.
The property name to monitor.
The expected increase delta (must be positive).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the given value is greater than the expected value.
This method checks if the provided value is numerically greater than the expected value. Works with both numbers and Date objects.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is greater than expected and throws AssertionFailure if it is not.
Asserts that the value is an array.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is not a number.
Asserts that the given value is greater than or equal to the expected value.
This method checks if the provided value is numerically greater than or equal to the expected value. Works with both numbers and Date objects.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is greater than or equal to expected and throws AssertionFailure if it is not.
Asserts that the given value is less than or equal to the expected value.
This method checks if the provided value is numerically less than or equal to the expected value. Works with both numbers and Date objects.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is less than or equal to expected and throws AssertionFailure if it is not.
Asserts that the given value is less than the expected value.
This method checks if the provided value is numerically less than the expected value. Works with both numbers and Date objects.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is less than expected and throws AssertionFailure if it is not.
Asserts that the value is a boolean.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is not a boolean.
Asserts that the provided value is empty, for strings, arrays, and objects, it checks if their length or size is zero. If the value is not empty, it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is empty and throws AssertionFailure if it is not.
This method checks if the provided value is an instance of the specified error or error constructor. If the value is not an instance of the specified error or error constructor, it throws an AssertionFailure with the given message.
That the value is an instance of the specified error or error constructor and throws AssertionFailure if it is not.
Asserts whether the value is extensible indicating whether new properties can be added to it. Primitive values are not extensible.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is not extensible.
Asserts that the given value is false.
This method checks if the provided value is strictly equal to false. If the value is not false,
it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is strictly false and throws AssertionFailure if it is not.
Asserts that the given value is a finite number (not NaN, not Infinity, not -Infinity).
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is not a finite number.
assert.isFinite(123); // Passes
assert.isFinite(0); // Passes
assert.isFinite(-456.789); // Passes
assert.isFinite(NaN); // Throws AssertionFailure
assert.isFinite(Infinity); // Throws AssertionFailure
assert.isFinite(-Infinity); // Throws AssertionFailure
assert.isFinite("123"); // Throws AssertionFailure
assert.isFinite(null); // Throws AssertionFailure
assert.isFinite(undefined); // Throws AssertionFailure
Asserts that the provided value is frozen and cannot have new properties added to it and its existing properties cannot be removed. If the value is not frozen, it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is frozen and throws AssertionFailure if it is not.
assert.isFrozen(Object.freeze({})); // Passes
assert.isFrozen(Object.freeze([])); // Passes
assert.isFrozen(Object.freeze("string")); // Passes
assert.isFrozen(Object.freeze({ key: "value" })); // Passes
assert.isFrozen({}); // Throws AssertionFailure
assert.isFrozen([]); // Throws AssertionFailure
assert.isFrozen("string"); // Throws AssertionFailure
assert.isFrozen({ key: "value" }); // Throws AssertionFailure
This method checks if the provided value is a function. If the value is not a function, it throws an AssertionFailure with the given message.
The value to evaluate.
OptionalinitMsg: MsgSourceThe message to display if value is not a function.
That the value is a function and throws AssertionFailure if it is not.
Asserts that the given value is an instance of the specified constructor.
Uses the JavaScript instanceof operator to check if the value is an instance of the constructor.
The value to check.
The constructor function to check against (e.g., Array, Date, Error, custom class).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
An AssertionFailure if the value is not an instance of the constructor.
assert.isInstanceOf(new Date(), Date); // Passes
assert.isInstanceOf([], Array); // Passes
assert.isInstanceOf(new Error(), Error); // Passes
assert.isInstanceOf({}, Object); // Passes
class MyClass {}
assert.isInstanceOf(new MyClass(), MyClass); // Passes
assert.isInstanceOf("hello", String); // Throws AssertionFailure
assert.isInstanceOf(123, Number); // Throws AssertionFailure
assert.isInstanceOf([], Object); // Passes (arrays are objects)
assert.isInstanceOf({}, Array); // Throws AssertionFailure
Asserts that the given value is an iterable, meaning it has a Symbol.iterator property.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is not an iterable.
assert.isIterable([]); // Passes
assert.isIterable(new Map()); // Passes
assert.isIterable(new Set()); // Passes
assert.isIterable({ [Symbol.iterator]: () => {} }); // Passes
assert.isIterable({}); // Throws AssertionFailure
assert.isIterable(null); // Throws AssertionFailure
assert.isIterable(undefined); // Throws AssertionFailure
Asserts that the given value is NaN.
This method checks if the provided value is the special numeric value NaN (Not-a-Number). Note that this only passes for actual NaN values, not for non-numeric types.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is NaN and throws AssertionFailure if it is not.
Asserts that the given value is not greater than the expected value.
This method checks if the provided value is not numerically greater than the expected value. Works with both numbers and Date objects. This is the inverse of isAbove.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is not greater than expected and throws AssertionFailure if it is.
Asserts that the value is not an array.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is an array.
Asserts that the given value is not greater than or equal to the expected value.
This method checks if the provided value is not numerically greater than or equal to the expected value. Works with both numbers and Date objects. This is the inverse of isAtLeast.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is not greater than or equal to expected and throws AssertionFailure if it is.
Asserts that the given value is not less than or equal to the expected value.
This method checks if the provided value is not numerically less than or equal to the expected value. Works with both numbers and Date objects. This is the inverse of isAtMost.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is not less than or equal to expected and throws AssertionFailure if it is.
Asserts that the given value is not less than the expected value.
This method checks if the provided value is not numerically less than the expected value. Works with both numbers and Date objects. This is the inverse of isBelow.
The value to check.
The expected value to compare against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is not less than expected and throws AssertionFailure if it is.
Asserts that the value is not a boolean.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is a boolean.
Asserts that the provided value is not empty, for strings, arrays, and objects, it checks if their length or size is greater than zero. If the value is empty, it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not empty and throws AssertionFailure if it is.
Asserts whether the value is not extensible indicating whether new properties can be added to it. Primitive values are not extensible.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails
An AssertionFailure if the value is extensible.
Asserts that the given value is not false.
This method checks if the provided value is not strictly equal to false. If the value is false,
it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not strictly false and throws AssertionFailure if it is.
Asserts that the given value is not a finite number (e.g., NaN, Infinity, -Infinity, or non-numeric).
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is a finite number.
assert.isNotFinite(NaN); // Passes
assert.isNotFinite(Infinity); // Passes
assert.isNotFinite(-Infinity); // Passes
assert.isNotFinite("123"); // Passes
assert.isNotFinite(null); // Passes
assert.isNotFinite(undefined); // Passes
assert.isNotFinite({}); // Passes
assert.isNotFinite(123); // Throws AssertionFailure
assert.isNotFinite(0); // Throws AssertionFailure
assert.isNotFinite(-456.789); // Throws AssertionFailure
Asserts that the provided value is not frozen and can have new properties added to it and its existing properties can be removed. If the value is frozen, it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not frozen and throws AssertionFailure if it is.
assert.isNotFrozen({}); // Passes
assert.isNotFrozen([]); // Passes
assert.isNotFrozen("string"); // Passes
assert.isNotFrozen({ key: "value" }); // Passes
assert.isNotFrozen(Object.freeze({})); // Throws AssertionFailure
assert.isNotFrozen(Object.freeze([])); // Throws AssertionFailure
assert.isNotFrozen(Object.freeze("string")); // Throws AssertionFailure
assert.isNotFrozen(Object.freeze({ key: "value" })); // Throws AssertionFailure
This method checks if the provided value is not a function. If the value is a function, it throws an AssertionFailure with the given message.
The value to evaluate.
OptionalinitMsg: MsgSourceThe message to display if value is a function.
That the value is not a function and throws AssertionFailure if it is.
assert.isNotFunction(null); // Passes
assert.isNotFunction(123); // Passes
assert.isNotFunction("string"); // Passes
assert.isNotFunction(() => {}); // Throws AssertionFailure
assert.isNotFunction(function() {}); // Throws AssertionFailure
assert.isNotFunction(async function() {}); // Throws AssertionFailure
Asserts that the given value is not an instance of the specified constructor.
Uses the JavaScript instanceof operator to check if the value is not an instance of the constructor.
The value to check.
The constructor function to check against (e.g., Array, Date, Error, custom class).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
An AssertionFailure if the value is an instance of the constructor.
assert.isNotInstanceOf("hello", Number); // Passes
assert.isNotInstanceOf(123, String); // Passes
assert.isNotInstanceOf({}, Array); // Passes
assert.isNotInstanceOf([], Date); // Passes
assert.isNotInstanceOf(new Date(), Date); // Throws AssertionFailure
assert.isNotInstanceOf([], Array); // Throws AssertionFailure
Asserts that the given value is not an iterable, meaning it does not have a Symbol.iterator property.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is an iterable.
assert.isNotIterable({}); // Passes
assert.isNotIterable(null); // Passes
assert.isNotIterable(undefined); // Passes
assert.isNotIterable([]); // Throws AssertionFailure
assert.isNotIterable(new Map()); // Throws AssertionFailure
assert.isNotIterable(new Set()); // Throws AssertionFailure
assert.isNotIterable({ [Symbol.iterator]: () => {} }); // Throws AssertionFailure
Asserts that the given value is not NaN.
This method checks if the provided value is not the special numeric value NaN (Not-a-Number).
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not NaN and throws AssertionFailure if it is.
Asserts that the given value is not null.
This method checks if the provided value is not strictly equal to null. If the value is null,
it throws an AssertionFailure with the given message.
That the value is not strictly null and throws AssertionFailure if it is.
Asserts that the value is not a number.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is a number.
This method checks if the provided value is not an object. If the value is an object, it throws an AssertionFailure with the given message.
That the value is not an object and throws AssertionFailure if it is.
Throws an AssertionFailure with the given message if value is not falsy.
This method is used to assert that a value is falsy.
The type of the value.
The value to evaluate. If the value is not falsy, an AssertionFailure is thrown.
OptionalinitMsg: MsgSourceThe message to display if value is not falsy. This can be a string or a function returning a string.
That the value is not truthy (falsy) and throws AssertionFailure if it is not.
assert.isNotOk(0); // Passes
assert.isNotOk(1); // Throws AssertionFailure
assert.isNotOk(true); // Throws AssertionFailure
assert.isNotOk(false); // Passes
assert.isNotOk(null); // Passes
assert.isNotOk(undefined); // Passes
assert.isNotOk(""); // Passes
assert.isNotOk("a"); // Throws AssertionFailure
assert.isNotOk([]); // Throws AssertionFailure
assert.isNotOk([1, 2]); // Throws AssertionFailure
assert.isNotOk({}); // Throws AssertionFailure
assert.isNotOk({ a: 1 }); // Throws AssertionFailure
assert.isNotOk(new Map()); // Throws AssertionFailure
assert.isNotOk(new Map([["a", 1]])); // Throws AssertionFailure
assert.isNotOk(new Set()); // Throws AssertionFailure
assert.isNotOk(new Set([1, 2])); // Throws AssertionFailure
assert.isNotOk(new Date()); // Throws AssertionFailure
This method checks if the provided value is not a plain object. If the value is a plain object, it throws an AssertionFailure with the given message.
A plain object is an object created by the object literal {} or with new Object().
It does not include instances of classes, arrays, or other objects.
That the value is not a plain object and throws AssertionFailure if it is.
assert.isNotPlainObject([]); // Passes
assert.isNotPlainObject(null); // Passes
assert.isNotPlainObject(123); // Passes
assert.isNotPlainObject("string"); // Passes
assert.isNotPlainObject({}); // Throws AssertionFailure
assert.isNotPlainObject(Object.create(null)); // Throws AssertionFailure
assert.isNotPlainObject(new Object()); // Throws AssertionFailure
Asserts that the provided value is not sealed and can have new properties added to it. If the value is sealed, it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not sealed and throws AssertionFailure if it is.
assert.isNotSealed({}); // Passes
assert.isNotSealed([]); // Passes
assert.isNotSealed({ key: "value" }); // Passes
assert.isNotSealed(Object.seal({})); // Throws AssertionFailure
assert.isNotSealed(Object.seal([])); // Throws AssertionFailure
assert.isNotSealed(Object.seal({ key: "value" })); // Throws AssertionFailure
Asserts that the value is not a string.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is a string.
Asserts that the given value is not true.
This method checks if the provided value is not strictly equal to true. If the value is true,
it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not strictly true and throws AssertionFailure if it is.
Asserts that the given value is not strictly undefined.
That the value is not strictly undefined and throws AssertionFailure if it is.
Asserts that the given value is not within the specified range (inclusive).
This method checks if the provided value is not within the given range. The range is inclusive, meaning the start and finish values are included. Works with both numbers and Date objects. This is the inverse of isWithin.
The value to check.
The start of the range (inclusive).
The end of the range (inclusive).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is not within start..finish and throws AssertionFailure if it is.
Asserts that the given value is null.
This method checks if the provided value is strictly equal to null. If the value is not null,
it throws an AssertionFailure with the given message.
That the value is strictly null and throws AssertionFailure if it is not.
Asserts that the value is a number.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is not a number.
This method checks if the provided value is an object. If the value is not an object, it throws an AssertionFailure with the given message.
That the value is an object and throws AssertionFailure if it is not.
Throws an AssertionFailure with the given message if value is not truthy.
This method is used to assert that a value is truthy.
The type of the value.
The value to evaluate. If the value is not truthy, an AssertionFailure is thrown.
OptionalinitMsg: MsgSourceThe message to display if value is not truthy. This can be a string or a function returning a string.
That the value is truthy and throws AssertionFailure if it is not.
assert.isOk(1); // Passes
assert.isOk("a"); // Passes
assert.isOk([]); // Passes
assert.isOk({}); // Passes
assert.isOk(new Map()); // Passes
assert.isOk(new Set()); // Passes
assert.isOk(new Date()); // Passes
assert.isOk(true); // Passes
assert.isOk(false); // Throws AssertionFailure
assert.isOk(0, "Value should be truthy"); // Throws AssertionFailure with message "Value should be truthy"
assert.isOk(""); // Throws AssertionFailure
assert.isOk(null); // Throws AssertionFailure
assert.isOk(undefined); // Throws AssertionFailure
This method checks if the provided value is a plain object. If the value is not a plain object, it throws an AssertionFailure with the given message.
A plain object is an object created by the object literal {} or with new Object().
It does not include instances of classes, arrays, or other objects.
That the value is a plain object and throws AssertionFailure if it is not.
assert.isPlainObject({}); // Passes
assert.isPlainObject(Object.create(null)); // Passes
assert.isPlainObject(new Object()); // Passes
assert.isPlainObject([]); // Throws AssertionFailure
assert.isPlainObject(null); // Throws AssertionFailure
assert.isPlainObject(123); // Throws AssertionFailure
assert.isPlainObject("string"); // Throws AssertionFailure
Asserts that the provided value is sealed and cannot have any new properties added to it. If the value is not sealed, it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is sealed and throws AssertionFailure if it is not.
assert.isSealed(Object.seal({})); // Passes
assert.isSealed(Object.seal([])); // Passes
assert.isSealed(Object.seal({ key: "value" })); // Passes
assert.isSealed({}); // Throws AssertionFailure
assert.isSealed([]); // Throws AssertionFailure
assert.isSealed({ key: "value" }); // Throws AssertionFailure
Asserts that the value is a string.
The value to check.
OptionalinitMsg: MsgSourceThe custom message to display if the assertion fails.
An AssertionFailure if the value is not a string.
Asserts that the given value is true.
This method checks if the provided value is strictly equal to true. If the value is not true,
it throws an AssertionFailure with the given message.
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is strictly true and throws AssertionFailure if it is not.
Asserts that the given value is strictly undefined.
That the value is strictly undefined and throws AssertionFailure if it is not.
Asserts that the given value is within the specified range (inclusive).
This method checks if the provided value is between the start and finish values (inclusive). Works with both numbers and Date objects.
The value to check.
The start of the range (inclusive).
The end of the range (inclusive).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That value is within the range [start, finish] and throws AssertionFailure if it is not.
Asserts that the target has a length or size property equal to the given number.
Works with arrays, strings, Maps, Sets, and any object with a length or size property.
That object has a length or size equal to length and throws AssertionFailure if it does not.
Asserts that the provided value matches the specified regular expression. If the value does not match the regular expression, it throws an AssertionFailure with the given message.
That the value matches the regular expression and throws AssertionFailure if it does not.
Asserts that the value contains the expected using nested property matching. Each property in the expected is matched against the value using dot notation.
That the value contains the expected using nested property matching and throws AssertionFailure if it does not.
Asserts that the provided value has the specified nested property using dot notation (e.g., "a.b.c"). Optionally checks the property value using loose equality (==). If the value does not have the nested property or the value doesn't match, it throws an AssertionFailure with the given message.
That the value has the specified nested property and throws AssertionFailure if it does not.
assert.nestedProperty({ a: { b: { c: 1 } } }, "a.b.c"); // Passes
assert.nestedProperty({ a: { b: 2 } }, "a.b.c"); // Throws AssertionFailure
assert.nestedProperty({ a: { b: { c: 1 } } }, "a.b.c", 1); // Passes
assert.nestedProperty({ a: { b: { c: 1 } } }, "a.b.c", "1"); // Passes (loose equality)
assert.nestedProperty({ a: { b: { c: 1 } } }, "a.b.c", 2); // Throws AssertionFailure
Alias for notCloseTo. Asserts that the actual value is NOT approximately equal to the expected value within the specified delta. This is the inverse of approximately.
The actual value to check. Must be a number.
The expected value to compare against. Must be a number.
The maximum allowed difference. Must be a number. Note: A negative delta will always result in a passing assertion since the absolute difference is always non-negative.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the value does NOT change by the specified delta after executing the target function. The value may remain unchanged, or change by a different amount. This is the negation of changesBy. For asserting that a change MUST occur but not by the specified amount, use changesButNotBy.
The function to execute.
A function that returns the value to monitor.
The delta that should NOT match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
let value = 0;
const getValue = () => value;
const addTwo = () => { value += 2; };
const noOp = () => {};
assert.notChangesBy(addTwo, getValue, 5); // Passes - changed by 2, not by 5
assert.notChangesBy(noOp, getValue, 5); // Passes - no change at all (not by 5)
assert.notChangesBy(addTwo, getValue, 2); // Fails - changed by exactly 2
Asserts that the property does NOT change by the specified delta after executing the target function. The value may remain unchanged, or change by a different amount. This is the negation of changesBy. For asserting that a change MUST occur but not by the specified amount, use changesButNotBy.
const obj = { count: 10 };
const addTwo = () => { obj.count += 2; };
const noOp = () => {};
assert.notChangesBy(addTwo, obj, 'count', 5); // Passes - changed by 2, not by 5
assert.notChangesBy(noOp, obj, 'count', 5); // Passes - no change at all (not by 5)
assert.notChangesBy(addTwo, obj, 'count', 2); // Fails - changed by exactly 2
Asserts that the actual value is NOT close to the expected value within the specified delta. This is the inverse of closeTo.
The actual value to check. Must be a number.
The expected value to compare against. Must be a number.
The maximum allowed difference. Must be a number. Note: A negative delta will always result in a passing assertion since the absolute difference is always non-negative.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function decreases the monitored value but NOT by the specified delta.
The function to execute that should decrease the value.
A function that returns the value to monitor.
The delta that should NOT match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function decreases the monitored object property but NOT by the specified delta.
Performs a deep inequality check between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is
deeply equal to the expected value. This method compares the values of all properties
of objects and elements of arrays.
The type of the values.
That the actual and expected values are not deeply equal and throws AssertionFailure if they are.
assert.notDeepEqual({ a: 1 }, { a: 2 }); // Passes
assert.notDeepEqual({ a: 1 }, { a: 1 }); // Throws AssertionFailure
assert.notDeepEqual([1, 2], [2, 1]); // Passes
assert.notDeepEqual([1, 2], [1, 2]); // Throws AssertionFailure
assert.notDeepEqual({ a: { b: 1 } }, { a: { b: 2 } }); // Passes
assert.notDeepEqual({ a: { b: 1 } }, { a: { b: 1 } }); // Throws AssertionFailure
assert.notDeepEqual([{ a: 1 }], [{ a: 2 }]); // Passes
assert.notDeepEqual([{ a: 1 }], [{ a: 1 }]); // Throws AssertionFailure
Performs a deep inequality check between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is
deeply equal to the expected value. This method compares the values of all properties
of objects and elements of arrays.
The type of the values.
That the actual and expected values are not deeply equal and throws AssertionFailure if they are.
assert.notDeepEquals({ a: 1 }, { a: 2 }); // Passes
assert.notDeepEquals({ a: 1 }, { a: 1 }); // Throws AssertionFailure
assert.notDeepEquals([1, 2], [2, 1]); // Passes
assert.notDeepEquals([1, 2], [1, 2]); // Throws AssertionFailure
assert.notDeepEquals({ a: { b: 1 } }, { a: { b: 2 } }); // Passes
assert.notDeepEquals({ a: { b: 1 } }, { a: { b: 1 } }); // Throws AssertionFailure
assert.notDeepEquals([{ a: 1 }], [{ a: 2 }]); // Passes
assert.notDeepEquals([{ a: 1 }], [{ a: 1 }]); // Throws AssertionFailure
Asserts that the value does NOT contain the expected using deep nested property matching.
That the value does not contain the expected using deep nested property matching and throws AssertionFailure if it does.
Asserts that the provided value does NOT have the specified nested property with a value that matches using deep equality.
That the value does not have the specified nested property with matching deep value and throws AssertionFailure if it does.
assert.notDeepNestedProperty({ a: { b: { c: { d: 1 } } } }, "a.b.d"); // Passes (property doesn't exist)
assert.notDeepNestedProperty({ a: { b: { c: { d: 1 } } } }, "a.b.d", { d: 1 }); // Passes (property doesn't exist)
assert.notDeepNestedProperty({ a: { b: { c: { d: 1 } } } }, "a.b.c", { d: 2 }); // Passes (value doesn't match)
assert.notDeepNestedProperty({ a: { b: { c: { d: 1 } } } }, "a.b.c", { d: 1 }); // Throws AssertionFailure
Asserts that the value does NOT contain the expected using deep own property matching. For objects, checks that not all keys in the expected are own properties (not inherited) or that values don't match using deep equality.
That the value does not deeply contain the expected using own property matching and throws AssertionFailure if it does.
assert.notDeepOwnInclude({ a: { b: 1 } }, { a: { b: 2 } }); // Passes
assert.notDeepOwnInclude({ a: 1 }, { b: 1 }); // Passes
assert.notDeepOwnInclude({ a: { b: 1 } }, { a: { b: 1 } }); // Throws AssertionFailure
// Inherited properties are not matched:
const obj = Object.create({ inherited: { deep: 1 } });
obj.own = { deep: 2 };
assert.notDeepOwnInclude(obj, { inherited: { deep: 1 } }); // Passes
Asserts that the target collection does not contain a subsequence matching the expected members using deep equality. This is the inverse of deepSubsequence. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection to check (must be an ArrayLikeOrSizedIterable).
The sequence to check against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the target collection does not end with the expected members in consecutive order at the end. This is the inverse of endsWithDeepMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not end with the expected sequence (must be an ArrayLikeOrSizedIterable).
The sequence to check against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the target collection does not end with the expected members in consecutive order at the end. This is the inverse of endsWithMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not end with the expected sequence (must be an ArrayLikeOrSizedIterable).
The sequence to check against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Throws an AssertionFailure with the given message if actual is equal to expected.
The type of the values.
That the actual and expected values are not loosely (!=) equal and throws AssertionFailure if they are.
assert.notEqual(1, 1); // Throws AssertionFailure
assert.notEqual(1, 2); // Passes
assert.notEqual("a", "a"); // Throws AssertionFailure
assert.notEqual("a", "b"); // Passes
assert.notEqual([1, 2], [1, 2]); // Passes
assert.notEqual([1, 2], [1, 2], "Arrays are equal"); // Throws AssertionFailure
assert.notEqual({ a: 1 }, { a: 1 }); // Passes
assert.notEqual({ a: 1 }, { a: 1 }, "Objects are equal"); // Throws AssertionFailure
assert.notEqual({ a: 1 }, { a: 2 }); // Passes
assert.notEqual({ a: 1 }, { a: 2 }, "Objects are equal"); // Throws AssertionFailure
assert.notEqual({ a: 1 }, { b: 1 }); // Passes
assert.notEqual({ a: 1 }, { b: 1 }, "Objects are equal"); // Throws AssertionFailure
assert.notEqual({ a: 1 }, { b: 2 }); // Passes
assert.notEqual({ a: 1 }, { b: 2 }, "Objects are equal"); // Throws AssertionFailure
Throws an AssertionFailure with the given message if actual is equal to expected.
The type of the values.
That the actual and expected values are not loosely (!=) equal and throws AssertionFailure if they are.
assert.notEquals(1, 1); // Throws AssertionFailure
assert.notEquals(1, 2); // Passes
assert.notEquals("a", "a"); // Throws AssertionFailure
assert.notEquals("a", "b"); // Passes
assert.notEquals([1, 2], [1, 2]); // Passes
assert.notEquals([1, 2], [1, 2], "Arrays are equal"); // Throws AssertionFailure
assert.notEquals({ a: 1 }, { a: 1 }); // Passes
assert.notEquals({ a: 1 }, { a: 1 }, "Objects are equal"); // Throws AssertionFailure
assert.notEquals({ a: 1 }, { a: 2 }); // Passes
assert.notEquals({ a: 1 }, { a: 2 }, "Objects are equal"); // Throws AssertionFailure
assert.notEquals({ a: 1 }, { b: 1 }); // Passes
assert.notEquals({ a: 1 }, { b: 1 }, "Objects are equal"); // Throws AssertionFailure
assert.notEquals({ a: 1 }, { b: 2 }); // Passes
assert.notEquals({ a: 1 }, { b: 2 }, "Objects are equal"); // Throws AssertionFailure
Asserts that the given value does not exist (is null or undefined).
The value to check.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is null or undefined and throws AssertionFailure if it is not.
Asserts that the provided value does NOT have the specified own property with a value that matches using deep equality.
That the value does not have the specified own property with matching deep value and throws AssertionFailure if it does.
Asserts that the provided value does NOT have the specified property with a value that matches using deep equality.
That the value does not have the specified property with matching deep value and throws AssertionFailure if it does.
Asserts that the provided value does NOT have the specified own property, or if a value is provided, that the own property value does NOT match using loose equality (==).
That the value does not have the specified own property (or value doesn't match) and throws AssertionFailure if it does.
Asserts that the provided value does NOT have the specified property, or if a value is provided, that the property value does NOT match using loose equality (==).
That the value does not have the specified property (or value doesn't match) and throws AssertionFailure if it does.
Asserts that the target does NOT have all of the specified keys using deep equality comparison. This method checks that at least one of the given keys does not exist in the target using deep equality for key comparison. This is the inverse of hasAllDeepKeys.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target does not have all of the specified keys and throws AssertionFailure if it does.
const obj = { greeting: "hello", subject: "friend" };
assert.notHaveAllDeepKeys(obj, "unknown"); // Passes - missing "unknown"
assert.notHaveAllDeepKeys(obj, ["greeting", "unknown"]); // Passes - missing "unknown"
const map = new Map([[{ id: 1 }, "value1"]]);
assert.notHaveAllDeepKeys(map, [{ id: 1 }, { id: 2 }]); // Passes - missing { id: 2 }
assert.notHaveAllDeepKeys(obj, ["greeting", "subject"]); // Throws AssertionFailure - has both keys
Asserts that the target does NOT have any of the specified keys using deep equality comparison. This method checks that none of the given keys exist in the target using deep equality for key comparison. This is the inverse of hasAnyDeepKeys.
The object, Map, or Set to check for keys.
The keys to search for (array, Set, Map, or other iterable of keys, or a single key).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the target does not have any of the specified keys and throws AssertionFailure if it does.
const obj = { greeting: "hello", subject: "friend" };
assert.notHaveAnyDeepKeys(obj, "unknown"); // Passes - does not have the key
assert.notHaveAnyDeepKeys(obj, ["unknown", "missing"]); // Passes - has neither key
const map = new Map([[{ id: 1 }, "value1"]]);
assert.notHaveAnyDeepKeys(map, [{ id: 3 }, { id: 4 }]); // Passes - has neither key
assert.notHaveAnyDeepKeys(obj, ["greeting", "unknown"]); // Throws AssertionFailure - has "greeting"
Asserts that the superset collection does not include all members of the subset collection with deep equality. This is the inverse of includeDeepMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not contain all members of the subset (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the superset collection does not include all members of the subset collection in the same order with deep equality. This is the inverse of includeDeepOrderedMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not contain all members of the subset in order (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the superset collection does not include all members of the subset collection. This is the inverse of includeMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not contain all members of the subset (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.notIncludeMembers([1, 2, 3], [1, 4]); // Passes - 4 not present
assert.notIncludeMembers([1, 2, 3], new Set([1, 4])); // Passes - Array vs Set
assert.notIncludeMembers(new Set([1, 2, 3]), [1, 4]); // Passes - Set vs Array
assert.notIncludeMembers([1, 2, 3, 4], [2, 3]); // Throws AssertionFailure - all present
assert.notIncludeMembers([1, 2, 3, 4], new Set([2, 3])); // Throws AssertionFailure - all present
Asserts that the superset collection does not include all members of the subset collection in the same order. This is the inverse of includeOrderedMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not contain all members of the subset in order (must be an ArrayLikeOrSizedIterable).
The collection of members to check for (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function increases the monitored value but NOT by the specified delta.
The function to execute that should increase the value.
A function that returns the value to monitor.
The delta that should NOT match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that executing the target function increases the monitored object property but NOT by the specified delta.
Asserts that the target does not have a length or size property equal to the given number.
Works with arrays, strings, Maps, Sets, and any object with a length or size property. This is the inverse of lengthOf.
That object does not have a length or size equal to length and throws AssertionFailure if it does.
Asserts that the provided value does NOT match the specified regular expression. If the value matches the regular expression, it throws an AssertionFailure with the given message. This is the inverse of match.
That the value does not match the regular expression and throws AssertionFailure if it does.
Asserts that the value does NOT contain the expected using nested property matching.
That the value does not contain the expected using nested property matching and throws AssertionFailure if it does.
Asserts that the provided value does NOT have the specified nested property using dot notation, or if a value is provided, that the nested property value does NOT match using loose equality (==).
That the value does not have the specified nested property (or value doesn't match) and throws AssertionFailure if it does.
assert.notNestedProperty({ a: { b: 2 } }, "a.b.c"); // Passes
assert.notNestedProperty({ a: { b: { c: 1 } } }, "a.b.c"); // Throws AssertionFailure
assert.notNestedProperty({ a: { b: { c: 1 } } }, "a.b.c", 2); // Passes
assert.notNestedProperty({ a: { b: { c: 1 } } }, "a.b.c", 1); // Throws AssertionFailure
Asserts that the value is NOT a member of the given list. Uses strict equality (===) to check if the value is in the list. Supports arrays, array-like objects (with length), Sets, Maps, and other iterables with size. This is the inverse of oneOf.
The value to check.
The array, array-like, Set, Map, or other iterable of possible values to check against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
// With arrays
assert.notOneOf(5, [1, 2, 3]); // Passes
assert.notOneOf("x", ["a", "b", "c"]); // Passes
assert.notOneOf(1, [1, 2, 3]); // Throws AssertionFailure
assert.notOneOf("a", ["a", "b", "c"]); // Throws AssertionFailure
// With Sets
const mySet = new Set([1, 2, 3]);
assert.notOneOf(5, mySet); // Passes
Asserts that the value does NOT contain the expected using own property matching. For objects, checks that not all keys in the expected are own properties (not inherited) or that values don't match using strict equality (===).
That the value does not contain the expected using own property matching and throws AssertionFailure if it does.
assert.notOwnInclude({ a: 1 }, { a: 2 }); // Passes
assert.notOwnInclude({ a: 1 }, { b: 1 }); // Passes
assert.notOwnInclude({ a: 1 }, { a: 1 }); // Throws AssertionFailure
// Inherited properties are not matched:
const obj = Object.create({ inherited: 1 });
obj.own = 2;
assert.notOwnInclude(obj, { inherited: 1 }); // Passes
Asserts that the actual collection does not have the same deep members as the expected collection. This is the inverse of sameDeepMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection to check (must be an ArrayLikeOrSizedIterable).
The expected collection to compare against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.notSameDeepMembers([{a: 1}], [{a: 2}]); // Passes
assert.notSameDeepMembers([{a: 1}], new Set([{a: 2}])); // Passes - Array vs Set
assert.notSameDeepMembers(new Set([{a: 1}]), [{a: 2}]); // Passes - Set vs Array
assert.notSameDeepMembers([{a: 1}, {b: 2}], [{b: 2}, {a: 1}]); // Throws AssertionFailure
assert.notSameDeepMembers([{a: 1}], new Set([{a: 1}])); // Throws AssertionFailure
Asserts that the actual and expected collections do not have the same members in the same order. This is the inverse of sameDeepOrderedMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection (must be an ArrayLikeOrSizedIterable).
The expected collection (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the actual collection does not have the same members as the expected collection. This is the inverse of sameMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection to check (must be an ArrayLikeOrSizedIterable).
The expected collection to compare against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.notSameMembers([1, 2, 3], [1, 2]); // Passes - different length
assert.notSameMembers([1, 2, 3], [1, 2, 4]); // Passes - different members
assert.notSameMembers([1, 2, 3], new Set([1, 2, 4])); // Passes - different members
assert.notSameMembers(new Set([1, 2, 3]), [1, 2, 4]); // Passes - different members
assert.notSameMembers([1, 2, 3], [3, 2, 1]); // Throws AssertionFailure - same members
assert.notSameMembers([1, 2, 3], new Set([3, 2, 1])); // Throws AssertionFailure - same members
Asserts that the actual collection does not have the same ordered members as the expected collection. This is the inverse of sameOrderedMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection to check (must be an ArrayLikeOrSizedIterable).
The expected collection to compare against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the target does not have a size or length property equal to the given number.
Works with arrays, strings, Maps, Sets, and any object with a length or size property. This is the inverse of sizeOf.
That object does not have a length or size equal to length and throws AssertionFailure if it does.
Asserts that the target collection does not start with the expected members in consecutive order from the beginning. This is the inverse of startsWithDeepMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not start with the expected sequence (must be an ArrayLikeOrSizedIterable).
The sequence to check against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the target collection does not start with the expected members in consecutive order from the beginning. This is the inverse of startsWithMembers. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should not start with the expected sequence (must be an ArrayLikeOrSizedIterable).
The sequence to check against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Performs a strict in-equality check (!==) between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
exactly equal to the expected value. To perform a loose equality check (==), use
the assert.equal method.
The type of the values.
That the actual and expected values are strictly (===) equal and throws AssertionFailure if they are not.
Asserts that the target collection does not contain a subsequence matching the expected members. This is the inverse of subsequence. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection to check (must be an ArrayLikeOrSizedIterable).
The sequence to check against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the given value's type does not match the expected type string.
Uses the JavaScript typeof operator for type comparison.
Valid type strings include:
The value to check.
The type string that the value should not match.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is not of the specified type and throws AssertionFailure if it is.
assert.notTypeOf("hello", "number"); // Passes
assert.notTypeOf(123, "string"); // Passes
assert.notTypeOf(() => {}, "object"); // Passes
assert.notTypeOf({}, "function"); // Passes
assert.notTypeOf("hello", "string"); // Throws AssertionFailure
assert.notTypeOf(123, "number"); // Throws AssertionFailure
Throws an AssertionFailure with the given message if value is not truthy.
This method is used to assert that a value is truthy.
The type of the value.
The value to evaluate. If the value is not truthy, an AssertionFailure is thrown.
OptionalinitMsg: MsgSourceThe message to display if value is not truthy. This can be a string or a function returning a string.
That the value is truthy and throws AssertionFailure if it is not.
assert.ok(1); // Passes
assert.ok("a"); // Passes
assert.ok([]); // Passes
assert.ok({}); // Passes
assert.ok(new Map()); // Passes
assert.ok(new Set()); // Passes
assert.ok(new Date()); // Passes
assert.ok(true); // Passes
assert.ok(false); // Throws AssertionFailure
assert.ok(0, "Value should be truthy"); // Throws AssertionFailure with message "Value should be truthy"
assert.ok(""); // Throws AssertionFailure
assert.ok(null); // Throws AssertionFailure
assert.ok(undefined); // Throws AssertionFailure
Asserts that the value is a member of the given list. Uses strict equality (===) to check if the value is in the list. Supports arrays, array-like objects (with length), Sets, Maps, and other iterables with size.
The value to check.
The array, array-like, Set, Map, or other iterable of possible values to check against.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
// With arrays
assert.oneOf(1, [1, 2, 3]); // Passes
assert.oneOf("a", ["a", "b", "c"]); // Passes
assert.oneOf(true, [true, false]); // Passes
assert.oneOf(5, [1, 2, 3]); // Throws AssertionFailure
assert.oneOf("x", ["a", "b", "c"]); // Throws AssertionFailure
// With Sets
const mySet = new Set([1, 2, 3]);
assert.oneOf(2, mySet); // Passes
Asserts that value is compared to expected using the given operator and the result is true.
Supports comparison operators: ==, ===, <, >, <=, >=, !=, !==, typeof
The support for typeof is in the form of typeof XXX === "expected", where expected is the type name string.
The first value to compare.
The comparison operator to use.
The second value to compare.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.operator(1, "<", 2); // Passes
assert.operator(2, ">", 1); // Passes
assert.operator(1, "==", 1); // Passes
assert.operator(1, "===", 1); // Passes
assert.operator(1, "<=", 1); // Passes
assert.operator(1, ">=", 1); // Passes
assert.operator(1, "!=", 2); // Passes
assert.operator(1, "!==", 2); // Passes
assert.operator(1, "!==", "1"); // Passes - type difference
assert.operator(2, "<", 1); // Throws AssertionFailure
assert.operator(1, "=", 2); // Throws AssertionFailure - invalid operator
// Typeof operator
assert.operator("hello", "typeof", "string"); // Passes - simplistic type check
assert.operator(123, "typeof", "number"); // Passes
assert.operator(true, "typeof", "boolean"); // Passes
assert.operator(123, "typeof", "string"); // Throws AssertionFailure
Asserts that the value contains the expected using own property matching only. For objects, checks that all keys in the expected are own properties (not inherited) and that values match using strict equality (===).
That the value contains the expected using own property matching and throws AssertionFailure if it does not.
assert.ownInclude({ a: 1, b: 2 }, { a: 1 }); // Passes
assert.ownInclude({ a: 1, b: 2 }, { a: 1, b: 2 }); // Passes
assert.ownInclude({ a: 1 }, { a: 2 }); // Throws AssertionFailure
// Inherited properties are not matched:
const obj = Object.create({ inherited: 1 });
obj.own = 2;
assert.ownInclude(obj, { own: 2 }); // Passes
assert.ownInclude(obj, { inherited: 1 }); // Throws AssertionFailure
Asserts that the actual collection has the same members as the expected collection, regardless of order. Uses deep equality for comparison. Particularly useful for Maps which iterate over [key, value] pairs. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection to check (must be an ArrayLikeOrSizedIterable).
The expected collection to compare against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.sameDeepMembers([{a: 1}, {b: 2}], [{b: 2}, {a: 1}]); // Passes
assert.sameDeepMembers([[1, 2], [3, 4]], [[3, 4], [1, 2]]); // Passes
assert.sameDeepMembers([{a: 1}], new Set([{a: 1}])); // Passes - Array vs Set
assert.sameDeepMembers(new Set([{a: 1}, {b: 2}]), [{b: 2}, {a: 1}]); // Passes
// Maps iterate over [key, value] pairs, so use deep comparison
const map = new Map([[1, "a"], [2, "b"]]);
assert.sameDeepMembers(map, [[1, "a"], [2, "b"]]); // Passes
assert.sameDeepMembers([{a: 1}], [{a: 2}]); // Throws AssertionFailure
Asserts that the actual and expected collections have the same members in the same order. Uses deep equality for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection (must be an ArrayLikeOrSizedIterable).
The expected collection (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the actual collection has the same members as the expected collection, regardless of order. Uses strict equality (===) for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection to check (must be an ArrayLikeOrSizedIterable).
The expected collection to compare against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
assert.sameMembers([1, 2, 3], [3, 2, 1]); // Passes - same members, different order
assert.sameMembers([1, 2, 2, 3], [3, 2, 2, 1]); // Passes - duplicates handled
assert.sameMembers([1, 2, 3], new Set([3, 2, 1])); // Passes - Array vs Set
assert.sameMembers(new Set([1, 2, 3]), [3, 2, 1]); // Passes - Set vs Array
assert.sameMembers(new Set([1, 2, 3]), new Set([3, 2, 1])); // Passes - Set vs Set
assert.sameMembers([1, 2, 3], [1, 2]); // Throws AssertionFailure - different length
assert.sameMembers([1, 2, 3], [1, 2, 4]); // Throws AssertionFailure - different members
Asserts that the actual collection has the same members in the same order as the expected collection. Uses strict equality (===) for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The actual collection to check (must be an ArrayLikeOrSizedIterable).
The expected collection to compare against (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the target has a size or length property equal to the given number.
Works with arrays, strings, Maps, Sets, and any object with a length or size property.
That object has a length or size equal to length and throws AssertionFailure if it does not.
Asserts that the target collection starts with the expected members in consecutive order from the beginning. Uses deep equality for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should start with the expected sequence (must be an ArrayLikeOrSizedIterable).
The expected starting sequence (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the target collection starts with the expected members in consecutive order from the beginning. Uses strict equality (===) for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should start with the expected sequence (must be an ArrayLikeOrSizedIterable).
The expected starting sequence (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Performs a strict equality check (===) between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
exactly equal to the expected value. To perform a loose equality check (==), use
the assert.equal method.
The type of the values.
That the actual and expected values are strictly (===) equal and throws AssertionFailure if they are not.
assert.strictEqual(1, 1); // Passes
assert.strictEqual(1, "1"); // Throws AssertionFailure
assert.strictEqual(1, 2); // Throws AssertionFailure
assert.strictEqual("a", "a"); // Passes
assert.strictEqual("a", "b"); // Throws AssertionFailure
assert.strictEqual([1, 2], [1, 2]); // Throws AssertionFailure
assert.strictEqual([1, 2], [1, 2], "Arrays are not equal"); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { a: 1 }); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { a: 1 }, "Objects are not equal"); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { a: 2 }); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { a: 2 }, "Objects are not equal"); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { b: 1 }); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { b: 1 }, "Objects are not equal"); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { b: 2 }); // Throws AssertionFailure
assert.strictEqual({ a: 1 }, { b: 2 }, "Objects are not equal"); // Throws AssertionFailure
Performs a strict equality check (===) between the actual and expected values,
throwing an AssertionFailure with the given message when the actual value is not
exactly equal to the expected value. To perform a loose equality check (==), use
the assert.equal method.
The type of the values.
That the actual and expected values are strictly (!==) equal and throws AssertionFailure if they are not.
Asserts that the target collection contains a subsequence matching the expected members. The members must appear in the specified order but don't need to be consecutive - other elements can appear between them. Uses strict equality (===) for comparison. Both arguments must conform to ArrayLikeOrSizedIterable but can be different concrete types.
The collection that should contain the ordered subsequence (must be an ArrayLikeOrSizedIterable).
The expected ordered subsequence (must be an ArrayLikeOrSizedIterable).
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
Asserts that the given function throws an error that matches the specified error constructor,
error instance, and / or the message includes the content or matches the regex pattern.
If the function does not throw an error, or if the thrown error does not
match the specified criteria, it throws an AssertionFailure with the given message.
Both the errorLike and msgMatch parameters are optional, so this method can be used to
assert that the function throws an error without checking the error type or message.
The function to execute and check for thrown errors.
OptionalerrorLike: Error | ErrorConstructorThe error constructor, error instance, or message pattern to check against.
OptionalmsgMatch: string | RegExpThe partial message or pattern to check against the error message.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the function throws an error that matches the specified criteria and throws AssertionFailure if it does not.
assert.throws(() => { throw new Error("test"); }); // Passes
assert.throws(() => { throw new TypeError("test"); }, TypeError); // Passes
assert.throws(() => { throw new Error("test"); }, /test/); // Passes
assert.throws(() => { throw new Error("test"); }, Error, "test"); // Passes
assert.throws(() => {}); // Throws AssertionFailure
assert.throws(() => { throw new Error("test"); }, TypeError); // Throws AssertionFailure
assert.throws(() => { throw new Error("test"); }, /nomatch/); // Throws AssertionFailure
Asserts that the given function throws an error and that the message contains the content
or matches the regex pattern.
If the function does not throw an error, or if the thrown error does not
match the specified criteria, it throws an AssertionFailure with the given message.
The msgMatch parameter is optional, so this method can be used to assert that the
function throws an error without checking the error type or message.
The function to execute and check for thrown errors.
OptionalmsgMatch: string | RegExpThe partial message or pattern to check against the error message.
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the function throws an error that matches the specified criteria and throws AssertionFailure if it does not.
assert.throws(() => { throw new Error("test"); }); // Passes
assert.throws(() => { throw new TypeError("test"); }, TypeError); // Passes
assert.throws(() => { throw new Error("test"); }, /test/); // Passes
assert.throws(() => { throw new Error("test"); }, Error, "test"); // Passes
assert.throws(() => {}); // Throws AssertionFailure
assert.throws(() => { throw new Error("test"); }, TypeError); // Throws AssertionFailure
assert.throws(() => { throw new Error("test"); }, /nomatch/); // Throws AssertionFailure
Asserts that the given value's type matches the expected type string.
Uses the JavaScript typeof operator for type comparison.
Valid type strings include:
The value to check.
The expected type string (e.g., "string", "number", "function").
OptionalinitMsg: MsgSourceThe message to display if the assertion fails.
That the value is of the specified type and throws AssertionFailure if it is not.
assert.typeOf("hello", "string"); // Passes
assert.typeOf(123, "number"); // Passes
assert.typeOf(() => {}, "function"); // Passes
assert.typeOf({}, "object"); // Passes
assert.typeOf(true, "boolean"); // Passes
assert.typeOf(Symbol(), "symbol"); // Passes
assert.typeOf(BigInt(123), "bigint"); // Passes
assert.typeOf(undefined, "undefined"); // Passes
assert.typeOf("hello", "number"); // Throws AssertionFailure
assert.typeOf(123, "string"); // Throws AssertionFailure
The
IAssertinterface defines the methods for performing assertions. This interface is used to ensure that certain conditions hold true during runtime. If an assertion fails, an AssertionFailure is thrown with an optional message.Since
0.1.0