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.
Optional
initMsg: 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
Optional
failMsg: MsgSourceThe optional message to include in the exception for the failure.
Optional
operator: 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.
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
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
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
Throws an AssertionFailure with the given message. This method is used to explicitly fail an assertion with a custom message.
Optional
initMsg: 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
Optional
failMsg: MsgSourceThe message to display.
Optional
operator: 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.
Optional
initMsg: MsgSourceThe message to display. This can be a string or a function returning a string.
AssertionFatal - Always.
Asserts that the provided value has the specified own property (i.e., a property that is not inherited). If the value does not have the own property, it throws an AssertionFailure with the given message.
That the value
has the specified own property and throws AssertionFailure if it does not.
Asserts that the provided value has the specified property. If the value does not have the property, it throws an AssertionFailure with the given message.
That the value
has the specified property and throws AssertionFailure if it does not.
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 the value is an array.
The value to check.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails.
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.
Optional
initMsg: 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. Primive values are not extensible.
The value to check.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails.
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.
Optional
initMsg: MsgSourceThe message to display if the assertion fails.
That the value
is strictly false
and throws AssertionFailure if it is not.
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.
Optional
initMsg: 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.
Optional
initMsg: 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 iterable, meaning it has a Symbol.iterator property.
The value to check.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails.
assert.isIterable([]); // Passes
assert.isIterable(new Map()); // Passes
assert.isIterable(new Set()); // Passes
assert.isIterable({ [Symbol.iterator]: () => {} }); // Passes
assert.isIterable({}); // Throws AssertionError
assert.isIterable(null); // Throws AssertionError
assert.isIterable(undefined); // Throws AssertionError
Asserts that the value is not an array.
The value to check.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails.
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.
Optional
initMsg: 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. Primive values are not extensible.
The value to check.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails
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.
Optional
initMsg: MsgSourceThe message to display if the assertion fails.
That the value
is not strictly false
and throws AssertionFailure if it is.
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.
Optional
initMsg: 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.
Optional
initMsg: 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 iterable, meaning it does not have a Symbol.iterator property.
The value to check.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails.
assert.isNotIterable({}); // Passes
assert.isNotIterable(null); // Passes
assert.isNotIterable(undefined); // Passes
assert.isNotIterable([]); // Throws AssertionError
assert.isNotIterable(new Map()); // Throws AssertionError
assert.isNotIterable(new Set()); // Throws AssertionError
assert.isNotIterable({ [Symbol.iterator]: () => {} }); // Throws AssertionError
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.
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.
Optional
initMsg: 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.
Optional
initMsg: 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.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails.
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.
Optional
initMsg: 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 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.
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.
Optional
initMsg: 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.
Optional
initMsg: 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.
Optional
initMsg: MsgSourceThe custom message to display if the assertion fails.
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.
Optional
initMsg: 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 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.
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
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
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.
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.
Optional
initMsg: 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
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 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.
Optional
errorLike: Error | ErrorConstructorThe error constructor, error instance, or message pattern to check against.
Optional
msgMatch: string | RegExpThe partial message or pattern to check against the error message.
Optional
initMsg: 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.
Optional
msgMatch: string | RegExpThe partial message or pattern to check against the error message.
Optional
initMsg: 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
The
IAssert
interface 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