Methods
areEqual(actual, expected, criteriaopt) → {void}
Expects two given objects to be equal according to a default or custom criteria. This is a shortcut of the that syntax followed by a isEqualTo assertion.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
actual |
*
|
the object under test. |
|
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.areEqual(3 + 4, 7)
equivalent version
assert.that('3' + '4').isEqualTo('34')
custom criteria
assert.areEqual([2, 3], ['x', 'y'], (a, b) => a.length === b.length)
areIdentical(actual, expected) → {void}
Expects two given objects to be identical, that is, to share the same reference. This is a shortcut of the that syntax followed by a isIdenticalTo assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the object under test. |
expected |
*
|
the object that you are expecting the |
Returns:
- Type:
-
void
Examples
literals
assert.areIdentical(3, 3)
equivalent version
assert.that(3).isIdenticalTo(3)
same reference
const object = { my: "object" }
assert.areIdentical(object, object)
areNotEqual(actual, expected, criteriaopt) → {void}
Expects two given objects to be not equal, according to a default or custom criteria. This is a shortcut of the that syntax followed by a isNotEqualTo assertion.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
actual |
*
|
the object under test. |
|
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.areNotEqual(3 + 4, 8)
equivalent version
assert.that('3' + '4').isNotEqualTo('7')
custom criteria
assert.areNotEqual([2, 3], ['x'], (a, b) => a.length === b.length)
isEmpty(actual) → {void}
Expects a given object to be an empty collection (arrays, strings, sets and maps). This is a shortcut of the that syntax followed by a isEmpty assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the collection object you expect to be empty. |
Returns:
- Type:
-
void
Examples
assert.isEmpty([])
assert.isEmpty('')
assert.isEmpty(new Set())
assert.isEmpty(new Map())
equivalent version
assert.that('').isEmpty()
isFalse(actual) → {void}
Expects a given object to be strictly equal to false
. Other "falsey" values according to Javascript rules
will be considered not true.
This is a shortcut of the that syntax followed by a isFalse assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the object you expect to be |
Returns:
- Type:
-
void
Examples
assert.isFalse(4 < 3)
equivalent version
assert.that(4 < 3).isFalse()
isMatching(actual, regex) → {void}
Expects a given string to match a given regexp. This is a shortcut of the that syntax followed by a matches assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
String
|
the string you will check against the regex. |
regex |
RegExp
|
the regexp you will use to parse the actual string. |
Returns:
- Type:
-
void
Examples
assert.isMatching('hello', /[a-z]+/)
equivalent version
assert.that('hello').matches(/[a-z]+/)
isNotEmpty(actual) → {void}
Expects a given object to be a non-empty collection (arrays, strings, sets and maps). This is a shortcut of the that syntax followed by a isNotEmpty assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the collection object you expect to be non-empty. |
Returns:
- Type:
-
void
Examples
assert.isNotEmpty([42])
assert.isNotEmpty('hello')
assert.isNotEmpty(new Set([42]))
assert.isNotEmpty(new Map([['key', 42]]))
equivalent version
assert.that('hello').isNotEmpty()
isNotNull(actual) → {void}
Expects the actual object to be different from null
.
This is a shortcut of the that syntax followed by a isNotNull assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the object you expect to be different from |
Returns:
- Type:
-
void
Examples
assert.isNotNull('something')
equivalent version
assert.that('something').isNotNull()
isNotUndefined(actual) → {void}
Expects the actual object to be not strictly equal to undefined
.
This is a shortcut of the that syntax followed by a isNotUndefined assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the object you expect to be not |
Returns:
- Type:
-
void
Examples
assert.isNotUndefined("hello".length)
equivalent version
assert.that("hello".length).isNotUndefined()
isNull(actual) → {void}
Expects the actual object to be strictly equal to null
.
This is a shortcut of the that syntax followed by a isNull assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the object you expect to be |
Returns:
- Type:
-
void
Examples
assert.isNull(null)
equivalent version
assert.that(null).isNull()
isTrue(actual) → {void}
Expects a given object to be strictly equal to true
. Other "truthy" values according to Javascript rules
will be considered not true.
This is a shortcut of the that syntax followed by a isTrue assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the object you expect to be |
Returns:
- Type:
-
void
Examples
assert.isTrue(3 < 4)
equivalent version
assert.that(3 < 4).isTrue()
isUndefined(actual) → {void}
Expects the actual object to be strictly equal to undefined
.
This is a shortcut of the that syntax followed by a isUndefined assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
the object you expect to be |
Returns:
- Type:
-
void
Examples
assert.isUndefined(object.missingProperty)
equivalent version
assert.that(object.missingProperty).isUndefined()
that(actual) → {Assertion}
Starts an assertion. A call to this method needs to be chained with an expectation, otherwise it does not represent a valid assertion.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
actual |
*
|
ths object under test. |
Examples
using the isEqualTo assertion
assert.that(3 + 4).isEqualTo(7)
using the isEmpty assertion
assert.that("").isEmpty()
using the isNearTo assertion
assert.that(0.1 + 0.2).isNearTo(0.3)