Classes
Methods
doesNotRaise(notExpectedError) → {void}
Expects the actual object (in this case, a function) to not raise an exception that matches the given criteria.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
notExpectedError |
any
|
RegExp
|
the error object expected not to be thrown or a Regex that should not match with the actual error message. |
Returns:
- Type:
-
void
Examples
exact error object
assert.that(() => throw new Error("oops")).doesNotRaise(new Error("ay!"))
regular expression
assert.that(() => throw new Error("oops")).doesNotRaise(/ay/)
doesNotRaiseAnyErrors() → {void}
Expects the actual object (in this case, a function) to not raise any exception at all. This is the most accurate way to ensure that a piece of code does not fail.
- Source:
Returns:
- Type:
-
void
Example
assert.that(() => 42).doesNotRaiseAnyErrors()
includes(expectedObject, equalityCriteriaopt) → {void}
Expects the actual collection object to include an expected object. Works for Array, Strings, Set and Maps. It works in the same way as isIncludedIn but swapping actual and expected objects.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
expectedObject |
*
|
the object that you are expecting to be included. |
|
equalityCriteria |
function
|
<optional> |
a two-argument function to be used to compare elements from the |
Returns:
- Type:
-
void
Examples
array
assert.that([1, 2, 3]).includes(2)
set
assert.that(new Set([1, 2, 3])).includes(3)
string
assert.that('42').includes('4')
isEmpty() → {void}
Expects the actual object to be an empty collection (arrays, strings, sets and maps). Another way of writing this assertion is to use the isEmpty method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that([]).isEmpty()
assert.that('').isEmpty()
assert.that(new Set()).isEmpty()
assert.that(new Map()).isEmpty()
equivalent version
assert.isEmpty('')
isEqualTo(expected, criteriaopt) → {void}
Expects the actual object to be equal to an expected object, according to a default or custom criteria. Another way of writing this assertion is to use the areEqual method.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
expected |
*
|
the object that you are expecting the |
|
criteria |
function
|
<optional> |
a two-argument function to be used to compare |
Returns:
- Type:
-
void
Examples
assert.that('3' + '4').isEqualTo('34')
equivalent version
assert.areEqual(3 + 4, 7)
custom criteria
assert.that([2, 3]).isEqualTo(['x', 'y'], (a, b) => a.length === b.length)
isFalse() → {void}
Expects the actual object to be strictly equal to false
. Other "falsy" values according to Javascript rules
will be considered not false.
Another way of writing this assertion is to use the isFalse method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that(3 >= 4).isFalse()
equivalent version
assert.isFalse(3 >= 4)
isGreaterThan(number) → {void}
Expects the actual object (in this case, a number) to be strictly greater than the given one.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
number |
Number
|
number to compare against the actual value. |
Returns:
- Type:
-
void
Example
assert.that(4).isGreaterThan(3)
isGreaterThanOrEqualTo(number) → {void}
Expects the actual object (in this case, a number) to be greater or equal than the given one.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
number |
Number
|
number to compare against the actual value. |
Returns:
- Type:
-
void
Example
assert.that(4).isGreaterThanOrEqualTo(4)
isIdenticalTo(expected) → {void}
Expects the actual object to be identical (be the same reference) to an expected one. Another way of writing this assertion is to use the areIdentical method.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
expected |
*
|
the object that you are expecting the |
Returns:
- Type:
-
void
Examples
literals
assert.that(3).isIdenticalTo(3)
equivalent version
assert.areIdentical(3, 3)
same reference
const object = { my: "object" }
assert.that(object).isIdenticalTo(object)
isIncludedIn(expectedCollection, equalityCriteriaopt) → {void}
Expects the actual object to be included on an expected collection. Works for Array, Strings, Set and Maps. It works in the same way as includes but swapping actual and expected objects.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
expectedCollection |
*
|
the collection that you are expecting the |
|
equalityCriteria |
function
|
<optional> |
a two-argument function to be used to compare elements from the |
Returns:
- Type:
-
void
Examples
array
assert.that(2).isIncludedIn([1, 2, 3])
set
assert.that(3).isIncludedIn(new Set([1, 2, 3]))
string
assert.that('lo').isIncludedIn('hello')
isLessThan(number) → {void}
Expects the actual object (in this case, a number) to be strictly less than the given one.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
number |
Number
|
number to compare against the actual value. |
Returns:
- Type:
-
void
Example
assert.that(3).isLessThan(4)
isLessThanOrEqualTo(number) → {void}
Expects the actual object (in this case, a number) to be less or equal than the given one.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
number |
Number
|
number to compare against the actual value. |
Returns:
- Type:
-
void
Example
assert.that(4).isLessThanOrEqualTo(4)
isNotEmpty() → {void}
Expects the actual object to be a non-empty collection (arrays, strings, sets and maps). Another way of writing this assertion is to use the isNotEmpty method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that([42]).isNotEmpty()
assert.that('hello').isNotEmpty()
assert.that(new Set([42])).isNotEmpty()
assert.that(new Map([['key', 42]])).isNotEmpty()
equivalent version
assert.isNotEmpty('hello')
isNotEqualTo(expected, criteriaopt) → {void}
Expects the actual object to be not equal to an expected object, according to a default or custom criteria. Another way of writing this assertion is to use the areNotEqual method.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
expected |
*
|
the object that you are expecting the |
|
criteria |
function
|
<optional> |
a two-argument function to be used to compare |
Returns:
- Type:
-
void
Examples
assert.that('3' + '4').isNotEqualTo('7')
equivalent version
assert.areNotEqual(3 + 4, 8)
custom criteria
assert.that([2, 3]).isNotEqualTo(['x'], (a, b) => a.length === b.length)
isNotNull() → {void}
Expects the actual object to be different from null
.
Another way of writing this assertion is to use the isNotNull method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that('something').isNotNull()
equivalent version
assert.isNotNull('something')
isNotUndefined() → {void}
Expects the actual object to be not strictly equal to undefined
.
Another way of writing this assertion is to use the isNotUndefined method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that("hello".length).isNotUndefined()
equivalent version
assert.isNotUndefined("hello".length)
isNull() → {void}
Expects the actual object to be strictly equal to null
.
Another way of writing this assertion is to use the isNull method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that(null).isNull()
equivalent version
assert.isNull(null)
isTrue() → {void}
Expects the actual object to be strictly equal to true
. Other "truthy" values according to Javascript rules
will be considered not true.
Another way of writing this assertion is to use the isTrue method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that(3 < 4).isTrue()
equivalent version
assert.isTrue(3 < 4)
isUndefined() → {void}
Expects the actual object to be strictly equal to undefined
.
Another way of writing this assertion is to use the isUndefined method.
- Source:
Returns:
- Type:
-
void
Examples
assert.that(object.missingProperty).isUndefined()
equivalent version
assert.isUndefined(object.missingProperty)
raises(errorExpectation) → {void}
Expects the actual object (in this case, a function) to raise an exception that matches the given expectation.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
errorExpectation |
any
|
RegExp
|
the error object expected to be thrown or a Regex that matches with the actual error message. |
Returns:
- Type:
-
void
Examples
exact error object
assert.that(() => throw new Error("oops")).raises(new Error("oops"))
regular expression
assert.that(() => throw new Error("oops I did it again")).raises(/oops/)